Variable list depending on groups

12 views
Skip to first unread message

paul.l...@prism-dm.co.uk

unread,
Jul 9, 2015, 12:02:16 PM7/9/15
to ansible...@googlegroups.com
I am using the zabbix_hosts module.

Depending on the groups that a particular host is in, I need to link to various Zabbix templates.

So:
if a server is in dbservers I need to link it to "Template App MySQL"
if a server is in webservers I need to link it to "Template App HTTP Service"

If a server is in both groups, it needs to be linked to both the above templates.
Additionally all the servers need to be linked to "Template OS Linux"

So in the module group, the "setting link_templates:" will end up needing to be fed values such as:


      link_templates:
        - Template OS Linux
        - Template App MySQL


      link_templates:
        - Template OS Linux
        - Template App HTTP Service

      link_templates:
        - Template OS Linux
        - Template App HTTP Service
        - Template App MySQL

Of course, this is only a small subset of the possible groups/templates.

Can someone suggest a neat way to build up the list so that I can code the task as something like:

  - name: Create a new host or update an existing host's info
    local_action:
      module: zabbix_host
      server_url: http://zabbix.server/
      login_user: ansible
      login_password: ansible_password
      host_name: "{{ inventory_hostname }}"
      host_groups:
        - Linux servers
      link_templates: "{{ templates_list }}"
      status: enabled
      state: present
      interfaces:

TIA
Reply all
Reply to author
Forward
0 new messages