Hello,
I have a setup in google cloud which has been working very well with Ansible. Till last week, we had only one "environment" per machine. Each environment was marked by a network tag which ansible would pick up while using limit. This worked beautifully.
Now, we are trying to consolidate some machines, ones that have our database. Thus, we have 2 environments together e.g. tag_dev and tag_test on one machine.
This has caused a bug where one of my play fails because ansible always picks a particular tag.
$ cat inventory/group_vars/tag_dev
---
environment_tag: "tag_dev"
$ cat inventory/group_vars/tag_test
---
environment_tag: "tag_test"
$ cat db.yml
---
- hosts: "tag_db"
user: admin
roles:
- {role: db, tag: db}
$ cat roles/db/tasks/main.yml
---
- debug:
var: "environment_tag"
- name: Ensure nginx location is updated
template:
src: "nginx/location.conf.j2"
dest: "/etc/nginx/locations/monit-{{ ansible_hostname }}.conf"
delegate_to: "{{ hostvars[(groups['tag_web'] | intersect(groups[environment_tag]))[0]]['internal_ip_address'] }}"
Now, when I run the playbook, I limit them by environment.
$ ansible-playbook -i inventory/gce.py db.yml --limit tag_dev
or
$ ansible-playbook -i inventory/gce.py db.yml --limit tag_test
earlier it would pick up environment_tag correctly, but not it picks tag_test with either of the limit applied. Is there a way I can use the tag from applied limit inside the play without having to pass an additional parameter?
--
With Regards,
Mehul Ved