Hi
There are 100 cassandra hosts (cass01.example.com,...,cass100.example.com)
All shall have the same role common and the same role cassandra.
In addition, 10 out of the 100 cassandra hosts do have additional
host-specific configurations
and to make things worse, these configurations differ across the 10 hosts.
The 10 cassandra hosts shall be
cass40.example.com,...,cass49.example.com. Finally, the additional
host-specific configurations
should be applied after the role common and role cassandra.
To solve this problem, I created a role for each
cass40.example.com,...,cass49.example.com.
Each role has the tasks which are specific to that host:
../roles/common
cassandra
cass40.example.com/tasks/main.yml
...
cass49.example.com/tasks/main.yml
Inventory file:
(..)
[cassandra]
cass01.example.com
...
cass100.example.com
(..)
The playbook has the two roles common and cassandra and an additional third
role called "{{ inventory_hostname }}"
when a host has a defined variable "has_own_role " in a file
../host_vars/cassxx.example.com. The variable
"{{ inventory_hostname }}" is equal to the FQDN written in the inventory
file.
- hosts: [cassandra}
user: ansible
sudo: yes
roles:
- common
- cassandra
- { role: "{{ inventory_hostname }}" , when: has_own_role is defined }
The files in ../host_vars/.. are:
cat ../host_vars/cass40.example.com
has_own_role: True
..
cat ../host_vars/cass49.example.com
has_own_role: True
When the playbook is run, ansilbe complains that there is no role {{
inventory_hostname }}:
...
ERROR: cannot find role in /data/ansible/roles/{{ inventory_hostname }} or
/data/ansible/{{ inventory_hostname }} or /etc/ansible/roles/{{
inventory_hostname }}
...
However, if I hard code a fix role (foo), the playbook works as intended :
...
- { role: foo , when: has_own_role is defined }
...
Queston 1:
Is there a way to provide a role name as a variable in the following line
instead of a fixed string (foo) ?
...
- { role: foo , when: has_own_role is defined }
...
Question 2;
In general, I do not know how to deal with the following (common) situation
in Ansible:
There is a bunch of equal hosts (cassandra) in the data center, but a few
of them a some random additional configurations
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/3d0b1a11-3150-4ab9-a2e2-597c5f5090f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.