Skip to content

Commit 78dd372

Browse files
feat: Add support for configuring provider URL and auto-update settings (#99)
* Mirrored the block style from debian 12 to make it easier to read * Added support to override how the client gets its providers * Fixed linting warnings * Eliminate duplicate run when updating the PR branch --------- Signed-off-by: Gary Bright <gary@mondoo.com>
1 parent a6c9057 commit 78dd372

10 files changed

Lines changed: 159 additions & 30 deletions

File tree

.github/workflows/ansible-ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ name: CI
33

44
on:
55
push:
6+
branches: [main]
67
pull_request:
8+
branches: [main]
79
workflow_dispatch:
810

911
jobs:

.yamllint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extends: default
44
ignore: |
55
*.mql.yaml
66
.github/workflows/*.yaml
7+
molecule-env/
78

89
rules:
910
braces:
@@ -14,3 +15,9 @@ rules:
1415
level: error
1516
line-length: disable
1617
truthy: disable
18+
comments:
19+
min-spaces-from-content: 1
20+
comments-indentation: false
21+
octal-values:
22+
forbid-implicit-octal: true
23+
forbid-explicit-octal: true

defaults/main.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# defaults file for mondoo
66

77
use_become: true
8-
latest_version_url: https://releases.mondoo.com/mondoo/latest.json
8+
mondoo_releases_base_url: "https://releases.mondoo.com"
9+
latest_version_url: "{{ mondoo_releases_base_url }}/mondoo/latest.json"
910

1011
# option to force a re-registration
1112
force_registration: false
@@ -20,6 +21,15 @@ splay: "60"
2021
# annotation/ tags for the node
2122
annotations: ""
2223

24+
# registration token for mondoo platform
25+
registration_token: ""
26+
27+
# proxy configuration
28+
proxy_env: {}
29+
30+
# ensure clients are managed in mondoo platform
31+
ensure_managed_client: false
32+
2333
# Update Task for cnspec (Linux)
2434
update_linux_enabled: false
2535
update_linux_cron_day: "*/3"
@@ -35,21 +45,26 @@ update_windows_time: "12:00:00"
3545
mondoo_gpg_keyid: 4CE909E26AE7439C39CE7647AC69C65100E1C42B
3646

3747
# deb repo
38-
mondoo_deb_repo_base_url: "https://releases.mondoo.com/debian/"
48+
mondoo_deb_repo_base_url: "{{ mondoo_releases_base_url }}/debian/"
3949
mondoo_deb_repo: "{{ mondoo_deb_repo_base_url }} stable main"
40-
mondoo_deb_gpgkey: "https://releases.mondoo.com/debian/pubkey.gpg"
50+
mondoo_deb_gpgkey: "{{ mondoo_releases_base_url }}/debian/pubkey.gpg"
4151
mondoo_deb_gpgkey_dest: "/usr/share/keyrings/mondoo-archive-keyring.gpg"
4252

4353
# yum repo and keys
4454
# 'mondoo_subscription_manager_repo_id' explicitly excludes 'mondoo_rpm_*'
4555
mondoo_subscription_manager_repo_id: ""
46-
mondoo_rpm_repo: "https://releases.mondoo.com/rpm/$basearch/"
47-
mondoo_rpm_gpgkey: "https://releases.mondoo.com/rpm/pubkey.gpg"
56+
mondoo_rpm_repo: "{{ mondoo_releases_base_url }}/rpm/$basearch/"
57+
mondoo_rpm_gpgkey: "{{ mondoo_releases_base_url }}/rpm/pubkey.gpg"
4858

4959
# zypper repo
50-
mondoo_zypper_repo: "https://releases.mondoo.com/rpm/{{ ansible_userspace_architecture }}/"
51-
mondoo_zypper_gpgkey: "https://releases.mondoo.com/rpm/pubkey.gpg"
60+
mondoo_zypper_repo: "{{ mondoo_releases_base_url }}/rpm/{{ ansible_userspace_architecture }}/"
61+
mondoo_zypper_gpgkey: "{{ mondoo_releases_base_url }}/rpm/pubkey.gpg"
5262

5363
# download and transfer
5464
mondoo_download_path: /tmp/mondoo_cache/
5565
mondoo_tmp_windows: "{{ ansible_env.TEMP }}\\s1_install"
66+
67+
# providers configuration
68+
mondoo_default_providers_url: "{{ mondoo_releases_base_url }}/providers"
69+
mondoo_providers_url: "{{ mondoo_default_providers_url }}"
70+
mondoo_providers_autoupdate: true

molecule/default/verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
ansible.builtin.file:
1414
path: "{{ cnspec_test_directory }}"
1515
state: directory
16-
mode: 0644
16+
mode: '0644'
1717
- name: Copy cnspec policies to remote
1818
ansible.builtin.copy:
1919
src: "{{ item }}"
2020
dest: "{{ cnspec_test_directory }}/{{ item | basename }}"
21-
mode: 0644
21+
mode: '0644'
2222
with_fileglob:
2323
- "{{ playbook_dir }}/tests/*mql.yaml"
2424
- name: Register test files

tasks/linux.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@
2727
- name: Login to Mondoo Platform
2828
ansible.builtin.include_tasks: linux_login.yml
2929
when: registration_token != ""
30+
31+
- name: Configure Mondoo providers
32+
ansible.builtin.include_tasks: linux_providers.yml

tasks/linux_login.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@
107107
- name: Ensure cnquery and cnspec are managed
108108
ansible.builtin.command: cnspec login
109109
become: "{{ use_become }}"
110-
when: (ensure_managed_client is not undefined and ensure_managed_client) and not ansible_check_mode
110+
when: ensure_managed_client and not ansible_check_mode

tasks/linux_providers.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) Mondoo, Inc.
2+
# SPDX-License-Identifier: BUSL-1.1
3+
4+
---
5+
6+
- name: Ensure mondoo config directory exists
7+
ansible.builtin.file:
8+
dest: /etc/opt/mondoo
9+
state: directory
10+
mode: '0644'
11+
become: "{{ use_become }}"
12+
when: not ansible_check_mode
13+
14+
- name: Check if mondoo.yml exists
15+
ansible.builtin.stat:
16+
path: /etc/opt/mondoo/mondoo.yml
17+
register: mondoo_config_file
18+
19+
- name: Create minimal mondoo.yml if it doesn't exist (no registration token scenario)
20+
ansible.builtin.file:
21+
path: /etc/opt/mondoo/mondoo.yml
22+
state: touch
23+
mode: '0600'
24+
become: "{{ use_become }}"
25+
when:
26+
- not ansible_check_mode
27+
- not mondoo_config_file.stat.exists
28+
29+
- name: Configure providers_url in mondoo.yml (when different from default)
30+
ansible.builtin.lineinfile:
31+
path: /etc/opt/mondoo/mondoo.yml
32+
regexp: '^providers_url:'
33+
line: 'providers_url: {{ mondoo_providers_url }}'
34+
mode: '0600'
35+
become: "{{ use_become }}"
36+
when:
37+
- not ansible_check_mode
38+
- mondoo_providers_url != mondoo_default_providers_url
39+
40+
- name: Configure auto_update in mondoo.yml (only when disabled)
41+
ansible.builtin.lineinfile:
42+
path: /etc/opt/mondoo/mondoo.yml
43+
regexp: '^auto_update:'
44+
line: 'auto_update: false'
45+
mode: '0600'
46+
become: "{{ use_become }}"
47+
when:
48+
- not ansible_check_mode
49+
- not mondoo_providers_autoupdate

tasks/pkg_debian.yml

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,52 @@
4040
update_cache: yes
4141
become: "{{ use_become }}"
4242

43-
- name: Install python3-debian for DEB822 repository support (Debian 13+)
44-
ansible.builtin.apt:
45-
name: python3-debian
46-
state: present
47-
update_cache: yes
48-
become: true
43+
- name: Configure repository for Debian 13+ (DEB822 format)
4944
when:
5045
- not ansible_check_mode
5146
- ansible_distribution == "Debian"
5247
- ansible_distribution_major_version | int >= 13
48+
block:
49+
- name: Install python3-debian for DEB822 repository support (Debian 13+)
50+
ansible.builtin.apt:
51+
name: python3-debian
52+
state: present
53+
update_cache: yes
54+
become: true
55+
retries: 3
56+
delay: 5
57+
register: python3_debian_install
58+
until: python3_debian_install is succeeded
5359

54-
- name: Configure Mondoo deb repository (DEB822 format)
55-
ansible.builtin.deb822_repository:
56-
name: mondoo
57-
types: deb
58-
uris: "{{ mondoo_deb_repo_base_url }}"
59-
suites: stable
60-
components: main
61-
signed_by: "{{ mondoo_deb_gpgkey }}"
62-
become: "{{ use_become }}"
63-
when:
64-
- not ansible_check_mode
65-
- ansible_distribution == "Debian"
66-
- ansible_distribution_major_version | int >= 13
60+
- name: Verify python3-debian installation
61+
ansible.builtin.command: python3 -c "import debian.deb822; print('DEB822 support available')"
62+
register: deb822_check
63+
changed_when: false
64+
failed_when: deb822_check.rc != 0
65+
66+
- name: Configure Mondoo deb repository (DEB822 format for Debian 13+)
67+
ansible.builtin.deb822_repository:
68+
name: mondoo
69+
types: deb
70+
uris: "{{ mondoo_deb_repo_base_url }}"
71+
suites: stable
72+
components: main
73+
signed_by: "{{ mondoo_deb_gpgkey }}"
74+
become: "{{ use_become }}"
75+
retries: 3
76+
delay: 5
77+
register: deb822_repo_config
78+
until: deb822_repo_config is succeeded
79+
80+
- name: Validate DEB822 repository configuration
81+
ansible.builtin.stat:
82+
path: /etc/apt/sources.list.d/mondoo.sources
83+
register: deb822_repo_file
84+
85+
- name: Ensure DEB822 repository file exists
86+
ansible.builtin.fail:
87+
msg: "DEB822 repository configuration failed - mondoo.sources file not found"
88+
when: not deb822_repo_file.stat.exists
6789

6890
- name: Ensure cnquery and cnspec are installed
6991
ansible.builtin.apt:

tasks/windows.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
ansible.windows.win_command: cnspec.exe login
165165
args:
166166
chdir: "C:\\Program Files\\Mondoo"
167-
when: (ensure_managed_client is not undefined and ensure_managed_client) and not ansible_check_mode
167+
when: ensure_managed_client and not ansible_check_mode
168168

169169
- name: Store update command as string (Scheduled Task)
170170
ansible.builtin.set_fact:
@@ -205,3 +205,6 @@
205205
state: present
206206
enabled: yes
207207
when: update_windows_enabled
208+
209+
- name: Configure Mondoo providers
210+
ansible.builtin.include_tasks: windows_providers.yml

tasks/windows_providers.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) Mondoo, Inc.
2+
# SPDX-License-Identifier: BUSL-1.1
3+
4+
---
5+
6+
- name: Ensure mondoo config directory exists
7+
ansible.windows.win_file:
8+
path: C:\ProgramData\Mondoo
9+
state: directory
10+
when: not ansible_check_mode
11+
12+
- name: Configure providers_url in mondoo.yml (when different from default)
13+
community.windows.win_lineinfile:
14+
path: C:\ProgramData\Mondoo\mondoo.yml
15+
regexp: '^providers_url:'
16+
line: 'providers_url: {{ mondoo_providers_url }}'
17+
when:
18+
- not ansible_check_mode
19+
- mondoo_providers_url != mondoo_default_providers_url
20+
21+
- name: Configure auto_update in mondoo.yml (only when disabled)
22+
community.windows.win_lineinfile:
23+
path: C:\ProgramData\Mondoo\mondoo.yml
24+
regexp: '^auto_update:'
25+
line: 'auto_update: false'
26+
when:
27+
- not ansible_check_mode
28+
- not mondoo_providers_autoupdate

0 commit comments

Comments
 (0)