Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate facts for all sites #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
state: restarted

- name: Reload Check_MK configuration
command: '/omd/sites/{{ checkmk_server__site }}/bin/cmk --reload'
command: '{{ checkmk_server__site_base }}/{{ checkmk_server__site }}/bin/cmk --reload'
environment:
OMD_ROOT: '/omd/sites/{{ checkmk_server__site }}'
OMD_ROOT: '{{ checkmk_server__site_base }}/{{ checkmk_server__site }}'

- name: Reload apache2
service:
Expand Down
8 changes: 1 addition & 7 deletions tasks/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- name: Create Check_MK site
command: omd create '{{ checkmk_server__site }}'
args:
creates: '/omd/sites/{{ checkmk_server__site }}/etc/omd/site.conf'
creates: '{{ checkmk_server__site_base }}/{{ checkmk_server__site }}/etc/omd/site.conf'

- name: Get Check_MK site version
command: omd version '{{ checkmk_server__site }}'
Expand Down Expand Up @@ -122,12 +122,6 @@
when: checkmk_server__sshkeys|d() and
"publickey_file" in checkmk_server__sshkeys|d()

- name: Read SSH public key
command: 'cat {{ checkmk_server__site_home }}/.ssh/id_rsa.pub'
changed_when: False
register: checkmk_server_register_ssh_pubkey
when: checkmk_server__sshkeys|d()

- name: Generate multisite permission roles definition
template:
src: 'etc/check_mk/multisite.d/wato/roles.mk.j2'
Expand Down
14 changes: 11 additions & 3 deletions templates/etc/ansible/facts.d/checkmk_server.fact.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"ssh_publickey": "{{ checkmk_server_register_ssh_pubkey.stdout }}"
}
{% set _site_filter = checkmk_server__site_base + "/*" %}
{% set _site_facts = {} %}
{% for _site in _site_filter | fileglob %}
{% set _site_name = _site | replace(checkmk_server__site_base + "/", "") %}
{% set _site_pubkey = _site + "/.ssh/id_rsa.pub" %}
{% set _pubkey = lookup("pipe", "sudo test -f " + _site_pubkey + " && sudo cat " + _site_pubkey + " || true") %}
{% if _pubkey %}
{% set _ = _site_facts.update({_site_name: {'ssh_publickey': _pubkey}}) %}
{% endif %}
{% endfor %}
{{ _site_facts | to_nice_json }}
5 changes: 4 additions & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---

# Check_MK site base
checkmk_server__site_base: '/opt/omd/sites'

# Check_MK site user name (mustn't exist before creating the site)
checkmk_server__user: '{{ checkmk_server__site }}'

# Check_MK site's user primary group name
checkmk_server__group: '{{ checkmk_server__site }}'

# Check_MK site chroot directory
checkmk_server__site_home: '/opt/omd/sites/{{ checkmk_server__site }}'
checkmk_server__site_home: '{{ checkmk_server__site_base }}/{{ checkmk_server__site }}'

# User properties used for user definition in users.mk
checkmk_server__user_properties: [ 'alias', 'automation_secret', 'connector',
Expand Down