I have the following inventory:
Test.inventory
[GroupA]
Host1
[GroupB]
Host1
GroupA and GroupB contain the same variables but with different values (e.g. filename). It seems that every time the playbook runs for this inventory, it does the steps once for the host (i.e. only for one of the groups).
What I want to achieve, is to run the playbook for Host1 twice (once for each group).
Is there any way to achieve this (maybe via roles)? Am I misusing the groups module?
The Ansible version I am using is 2.3.
Best Regards,
Konstantinos
Thanks a lot for your help! From what I understand is that the ansible_host should be the actual hostname (dns entry). Is there any way to pass the to the ansible_host the name of an entry in the host_vars?
For example, I have in the host_vars directory, the folder Host1 where it has a vars.yml where one of the variables is ansible_host: "1.2.3.4".
In order to use your approach I will need to add the ansible_host inline in the inventory like this:
[GroupA]
host1A ansible_host="1.2.3.4"
[GroupB]
host1B ansible_host="1.2.3.4"
What I would like to do is to have something like this
[GroupA]
host1A ansible_host=Host1
[GroupB]
host1B ansible_host=Host1
Is this feasible?
If it is not feasible, I will have to add all the variables in the inventory and this will not be so clean.
Best Regards,
Konstantinos
What I want to have is one host folder (i.e. Host1) which will contain a vars.yml that will define the actual ansible_host (i.e. "1.2.3.4"). So, in the inventory I will need to have:
[GroupA]
host1A ansible_host=Host1
[GroupB]
host1B ansible_host=Host1
where the ansible_host will take the name of the host folder (i.e. Host1) and will find the actual value for the ansible_host (i.e. "1.2.3.4") from the vars.yml.
What I understood is that by using the ansible_host variable in the inventory I have to give the actual value (i.e. "1.2.3.4") and it cannot take let's say a host alias (i.e. Host1).
Is there any other way to define which host folder to check in order to retrieve the ansible_host variable?
Best Regards,
Konstantinos
This is what I did and it didn't work. Different groups mean different configuration for my application (that is the reason of such distinction), so if I use HostA under both groups, it doesn't do the deployment twice in the same host but only for the last one.
Best Regards,
Konstantinos
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d3e09cc9-e792-4c63-8077-35be809ee8f2%40googlegroups.com.
*******************************************************************************
This e-mail and any of its attachments may contain Interactions LLC proprietary information, which is privileged, confidential, or subject to copyright belonging to the Interactions LLC. This e-mail is intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution, copying, or action taken in relation to the contents of and attachments to this e-mail is strictly prohibited and may be unlawful. If you have received this e-mail in error, please notify the sender immediately and permanently delete the original and any copy of this e-mail and any printout. Thank You.
*******************************************************************************
Finally we made it work using the following approach:
Inventory file:
Host1 mygroups='["groupA","groupB"]'
Created two playbook files one with the tasks (PlaybookTasks.yml) and one that does an iteration (Playbook.yml)
Playbook.yml:
---
- hosts: all
tasks:
- include: PlaybookTasks.yml mygroup="{{ item }}"
with_items: "{{ mygroups}}"
PlaybookTasks.yml:
- name: Include vars
include: "group_vars/{{ group}}/vars.yml"
- name: Download application
.....
The structure of the host_vars and group_vars remained as I initially explained.
Thank you all for the support and your prompt answers.
Best Regards,
Konstantinos