mondoo.client
MondooパッケージAnsibleロール
概要
このロールは、LinuxおよびWindowsサーバーにcnquery
とcnspec
をインストールします。
主な機能は以下の通りです:
- 署名された
cnquery
とcnspec
のバイナリをインストール - Mondooプラットフォームに
cnquery
とcnspec
を登録 - LinuxおよびWindowsで
cnspec
サービスを有効化
サポートされているオペレーティングシステム:
- Amazon Linux
- Debian
- Red Hat Enterprise Linux およびその派生版(CentOS/AlmaLinux/Rocky Linux)
- SUSE & openSUSE
- Ubuntu
- Windows 10, 11, 2016, 2019, 2022
このロールはAnsible Galaxyに公開されています:Mondoo/Client役割。
要件
- Ansible > 2.5
ロール変数
名前 | デフォルト値 | 説明 |
---|---|---|
registration_token_retrieval |
manual |
manual は``registration_token`を設定する必要があります |
registration_token |
n/a | cnquery とcnspec の登録に使用するMondooプラットフォームの登録トークンを手動で設定 |
force_registration |
false | 各実行で再登録を強制するかどうか |
依存関係
このロールには依存関係がありません。
例:AnsibleプレイブックをAmazon EC2 Linuxインスタンスに適用する
このプレイブックは、Mondooパッケージロールを使用して多くのインスタンスにcnquery
とcnspec
をインストールする方法を示します:
- 新しい
hosts
インベントリを作成し、ホストをグループに追加します。
[linux_hosts]
54.172.7.243 ansible_user=ec2-user
playbook.yml
を作成し、registration_token
を変更します:
---
- hosts: linux_hosts
become: yes
roles:
- role: ansible-mondoo # galaxyから使用する場合: mondoo.client
vars:
registration_token: "changeme"
さらに、以下の変数もサポートしています:
変数 | 説明 |
---|---|
force_registration: true |
cnquery とcnspec を再登録したい場合はtrueに設定 |
ensure_managed_client: true |
設定したクライアントがMondooの管理対象クライアントとして設定されていることを確認 |
proxy_env['https_proxy'] |
cnspec クライアントのプロキシを設定 |
annotations |
ノードにアノテーション/タグを設定 |
update_linux_enabled |
Linuxの更新タスクをcronジョブ経由で有効にしたい場合はtrueに設定 |
update_linux_cron_day |
cnspec の更新間隔を日単位で定義します。例:*/3は3日ごと |
update_linux_cron_hour |
タスクを実行する時間を定義 |
update_linux_cron_minute |
タスクを実行する分を定義 |
update_windows_enabled |
Windowsの更新タスクをスケジュールされたタスク経由で有効にしたい場合はtrueに設定 |
update_windows_interval |
cnspec の更新の間隔を日単位で定義 |
update_windows_time |
タスクを実行する時間を定義 |
timer |
スキャン間隔を分単位で設定します。デフォルトは60です。 |
splay |
スキャンタイミングの遅延を定義 |
---
- hosts: linux_hosts
become: yes
roles:
- role: ansible-mondoo # galaxyから使用する場合: mondoo.client
vars:
registration_token: "changeme"
force_registration: true
ensure_managed_client: true
annotations: "[email protected],env=production"
プロキシの背後でcnspecを使用する場合:
---
- hosts: linux_hosts
become: yes
vars:
proxy_env:
http_proxy: "http://192.168.56.1:3128"
https_proxy: "http://192.168.56.1:3128"
roles:
- role: ansible-mondoo # galaxyから使用する場合: mondoo.client
vars:
registration_token: "changeme"
force_registration: true
ensure_managed_client: true
environment: "{{proxy_env}}"
Windowsの更新タスクを使用する場合:
---
- hosts: windows_hosts
become: yes
roles:
- role: ansible-mondoo # galaxyから使用する場合: mondoo.client
vars:
registration_token: "changeme"
force_registration: true
ensure_managed_client: true
update_windows_enabled: true
update_windows_interval: "1"
update_windows_time: "15:04"
Linuxの更新タスクを使用する場合:
---
- hosts: linux_hosts
become: yes
roles:
- role: ansible-mondoo # galaxyから使用する場合: mondoo.client
vars:
registration_token: "changeme"
force_registration: true
ensure_managed_client: true
update_linux_enabled: true
update_linux_cron_day: "*"
update_linux_cron_hour: "11"
update_linux_cron_minute: "40"
- ローカルのホストファイルでプレイブックを実行します。
# GitHubからmondooロールをダウンロード
ansible-galaxy role install git+https://github.com/mondoohq/ansible-mondoo.git
# (代替) Ansible Galaxyからmondooロールをダウンロード
ansible-galaxy install mondoo.client
# プレイブックを適用
ansible-playbook -i hosts playbook.yml
- スキャン結果を表示するためにMondooコンソールにログインします。
AnsibleプレイブックをAmazon EC2 Windowsインスタンスに適用する
Windowsを使用している場合は、WinRMの設定またはSSHの設定についてのAnsibleのドキュメントを読んでください。
- 新しい
hosts
インベントリを作成し、ホストをグループに追加します。
[windows_hosts]
123.123.247.76 ansible_port=5986 ansible_connection=winrm ansible_user=Administrator ansible_password=changeme ansible_shell_type=powershell ansible_winrm_server_cert_validation=ignore
または、SSHを使用する場合:
3.235.247.76 ansible_port=22 ansible_connection=ssh ansible_user=admin ansible_shell_type=cmd
playbook.yml
を作成し、registration_token
を変更します:
Windowsをターゲットにする場合、設定は若干異なります。 become
を無効にする必要があります:
- hosts: windows_hosts
roles:
- role: ansible-mondoo # galaxyから使用する場合: mondoo.client
vars:
registration_token: "changeme"
force_registration: false
- ローカルのホストファイルでプレイブックを実行します。
# GitHubからmondooロールをダウンロード
ansible-galaxy role install git+https://github.com/mondoohq/ansible-mondoo.git
# (代替) Ansible Galaxyからmondooロールをダウンロード
ansible-galaxy install mondoo.client
# プレイブックを適用
ansible-playbook -i hosts playbook.yml
テスト
このロールはテストのためにMoleculeを使用します。依存関係をインストールするには:
pip install molecule
pip install docker
pip install 'molecule-plugins[docker]'
molecule
CLIはテストライフサイクルをカバーします:
# moleculeをリセット
molecule reset
# ansibleでマシンを収束
image=geerlingguy/docker-ubuntu2204-ansible molecule converge
# cnspecでmoleculeテストを実行
image=geerlingguy/docker-ubuntu2204-ansible molecule verify
# デバッグのために個々のホストにログイン
molecule login --host ubuntu
# テストセットアップを破棄
molecule destroy
image=geerlingguy/docker-ubuntu2204-ansible molecule test
image=rsprta/opensuse-ansible molecule test
注意:M1 macOSでテストするには、上記のRocky LinuxのようなARM互換のDockerイメージが必要です。
Lintingにはansible-lint
を使用します:
pip3 install ansible-lint
その後、ローカルの問題をすべて確認できます:
ansible-lint
著者
Mondoo, Inc
よくある質問
'module'オブジェクトに'HTTPSHandler'属性がありませんというエラー
TASK [mondoo : Download Mondoo RPM key] ********************************
fatal: [suse]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 127.0.0.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/home/vagrant/.ansible/tmp/ansible-tmp-1562450830.52-85510064926638/AnsiballZ_get_url.py\", line 113, in <module>\r\n _ansiballz_main()\r\n File \"/home/vagrant/.ansible/tmp/ansible-tmp-1562450830.52-85510064926638/AnsiballZ_get_url.py\", line 105, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/vagrant/.ansible/tmp/ansible-tmp-1562450830.52-85510064926638/AnsiballZ_get_url.py\", line 48, in invoke_module\r\n imp.load_module('__main__', mod, module, MOD_DESC)\r\n File \"/tmp/ansible_get_url_payload_103dVU/__main__.py\", line 308, in <module>\r\n File \"/tmp/ansible_get_url_payload_103dVU/ansible_get_url_payload.zip/ansible/module_utils/urls.py\", line 346, in <module>\r\nAttributeError: 'module' object has no attribute 'HTTPSHandler'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
sudo zypper install python python2-urllib3 python3 python3-urllib3
WindowsでSSHを使用している場合のansible.legacy.setup
のエラー
fatal: [123.123.247.76]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "Parameter format not correct - ;\r\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}
powershell
がシェルタイプの場合、Win32-OpenSSHのバージョンがv7.9.0.0p1-Betaより古い場合は正常に動作しません。シェルタイプをcmd
に設定してください。
'jmespath'をインストールする必要がありますというエラー
jmespathがansibleと同じPython環境にインストールされていることを確認してください:
pip install jmespath
サポートされていないOSでテストしたい
main.ymlに以下を追加し、ansible_factsを印刷して、何が使用されているかを確認し、when
条件を調整します:
- name: Print all available facts
ansible.builtin.debug:
var: ansible_facts
コミュニティに参加しよう!
MondooコミュニティGitHubディスカッションに参加して、政策のコーディングとセキュリティ自動化について共同作業をしましょう。
ansible-galaxy install mondoo.client