debops-contrib / ansible-checkmk_server

Setup Check_MK monitoring server
GNU General Public License v3.0
9 stars 3 forks source link

Generate facts for all sites #15

Closed ganto closed 8 years ago

ganto commented 8 years ago

Currently the checkmk_server role only allows you to manage one site. However, you may have multiple playbooks for multiple sites or manually manage other sites. If possible also generate facts for other sites, so that the checkmk_agent role can relate to them (see debops-contrib/ansible-checkmk_agent#15).

ganto commented 8 years ago

Fortunately I was hesitating with merging this. After playing around with it, I found out this doesn't work at all. The lookup plugin is executed on the Ansible controller which on my development machine used to be the same as the target server. If they are separate the facts template doesn't contain any valuable information. So this PR doesn't work as originally intended.

@ypid: I guess I need some help finding a good solution here. What I'm trying to do:

Optionally, I could do a delegate_to task in the agent role, which would query the SSH key specifically for the site it wants to register. Still, I find this solution somehow less appealing.

Any ideas, suggestions?

ypid commented 8 years ago

Lets see if I can help you here.

Optionally, I could do a delegate_to task in the agent role, which would query the SSH key specifically for the site it wants to register. Still, I find this solution somehow less appealing.

Hm, that seems to be the most straight forward way to do it. The second way would be to put the public key(s) on the monitoring servers in Ansible facts and play with accessing those facts from the nodes to monitor. That should work but I have never tried that. It might require facts caching or running against the monitoring servers in the same play.

If possible this should also work for manually created sites

Should be possible. I am not up-to-date with all the fancy stuff in Check_MK and OMD but I guess you can access the SSH public keys using a somewhat deterministic file path? Then you can just put that in Ansible facts.

As for how to do it. You can cat the public key using the command module and then put it in the facts file.

I tried to solve this by attempting to define dictionary facts with multiple keys. But this didn't work. Is this possible at all with Ansible?

If it can be expressed in JSON or YAML, then you can set it as Ansible facts. You might have to play a bit with Jinja to make it work but there is always a way. Maybe using a list like in:

---

_site_name:
  ssh_publickey:
    - pub key
    - pub key

would make sense. You can just append to a list in Jinja.

ypid commented 8 years ago

For the Jinja question. You could use a tmp variable to get started?

(Untested:)

{% set tmp = {{'ssh_publickey': _pubkey}) %}
{% set _ = tmp.update({'ssh_publickey2': _pubkey2}) %}
{% set _ = _site_facts.update({_site_name: tmp}) %}
ganto commented 8 years ago

It's not trivial to make my idea work with Ansible set_fact and Jinja2. So I first concentrate on integrating server and agent all being managed by DebOps and maybe comeback to this later again.