Hi all,
This is another issue I’m running with the migration from Chef to Ansible. In Chef you can use chef search in your code logic to do various things. We need to set a tag inside a config file for every role we run on the server the same way as Chef because our monitoring system aggregation metrics depends on these tags for reporting and alerting.
At the moment we have defined a variable named “role” under each role vars and if we deploy many roles in one server we have to populate the configuration file with all tags.
For example we have
roles :
common
web
db
application
In common we deploy the template :
- name: deploy /etc/monitoring.conf
template: src=monitoring.conf.j2 dest=/etc/monitoring.conf
monitoring.conf.j2
tags: env:{{ env }}, role:{{ role }}
We need the end result file to be something like :
tags: env: prod, role: common, role:web, role:db, role:application
-
Is there a way Ansible knows which role is running or I have to manually define a var for every role as I have in my example above ?
-
Most important how can I have all role tags in the configuration file and not only a singleton ? Can this be done in an idempotent way ?
Thanks in advance,
Nicolas.