Set hosts value with an extra-vars doesn't work for my Ansible role
up vote
0
down vote
favorite
I've got a problem with my ansible playbook :
My playbook is composed of 5 roles and looks like this :
---
- name: Création de la machine virtuelle Host_Name à l'aide du template vcenter_template
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/deploy
tags: deploy
- name: Configuration de l'échange de clé de root@lrtstfpe vers root@ Host_Name
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/pre_config
tags: pre_config
- name: Opérations post install
hosts: ' Host_Name '
gather_facts: no
roles:
- roles/VMWare/post_install
tags: post_install
- name: Ajout du pointeur DNS sur le controleur de domaine wpsrvctldom1.uem.lan
hosts: DNS
gather_facts: no
roles:
- roles/DNS/
tags: DNS
- name: Ajout du mot de passe Keepass de l'utilisateur root de la machine
hosts: DNS
gather_facts: no
roles:
- roles/Keepass/
tags: keepass
I launch this playbook with this command :
ansible-playbook playbook/deployVM.yml --extra-vars "Host_Name=toto"
My variable is correctly interpreted in my tasks name but my third role which use the value of this variable to do operations on the appropriate host is skipped and Ansible says "skipping: no hosts matched
".
But when I re-launch my playbook with "--tags post_install
" to play only this role... It works !
I don't know why when I launch the entire playbook it doesn't work and when I launch just the 3rd role.. It works..
Can someone help me ?
Thx :)
PS : I add my Host_Name
machine into /etc/ansible/hosts
file thanks to the 2nd role :
[VM]
toto
ansible ansible-2.x
add a comment |
up vote
0
down vote
favorite
I've got a problem with my ansible playbook :
My playbook is composed of 5 roles and looks like this :
---
- name: Création de la machine virtuelle Host_Name à l'aide du template vcenter_template
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/deploy
tags: deploy
- name: Configuration de l'échange de clé de root@lrtstfpe vers root@ Host_Name
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/pre_config
tags: pre_config
- name: Opérations post install
hosts: ' Host_Name '
gather_facts: no
roles:
- roles/VMWare/post_install
tags: post_install
- name: Ajout du pointeur DNS sur le controleur de domaine wpsrvctldom1.uem.lan
hosts: DNS
gather_facts: no
roles:
- roles/DNS/
tags: DNS
- name: Ajout du mot de passe Keepass de l'utilisateur root de la machine
hosts: DNS
gather_facts: no
roles:
- roles/Keepass/
tags: keepass
I launch this playbook with this command :
ansible-playbook playbook/deployVM.yml --extra-vars "Host_Name=toto"
My variable is correctly interpreted in my tasks name but my third role which use the value of this variable to do operations on the appropriate host is skipped and Ansible says "skipping: no hosts matched
".
But when I re-launch my playbook with "--tags post_install
" to play only this role... It works !
I don't know why when I launch the entire playbook it doesn't work and when I launch just the 3rd role.. It works..
Can someone help me ?
Thx :)
PS : I add my Host_Name
machine into /etc/ansible/hosts
file thanks to the 2nd role :
[VM]
toto
ansible ansible-2.x
"PS : I add my Host_Name machine into /etc/ansible/hosts file thanks to the 2nd role" does that mean before that 2nd role runs, thetoto
hostname isn't known to ansible? Because if so, I think you'll need to also useadd_host:
to teach the in-memory ansible about the host
– Matthew L Daniel
Nov 12 at 0:04
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've got a problem with my ansible playbook :
My playbook is composed of 5 roles and looks like this :
---
- name: Création de la machine virtuelle Host_Name à l'aide du template vcenter_template
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/deploy
tags: deploy
- name: Configuration de l'échange de clé de root@lrtstfpe vers root@ Host_Name
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/pre_config
tags: pre_config
- name: Opérations post install
hosts: ' Host_Name '
gather_facts: no
roles:
- roles/VMWare/post_install
tags: post_install
- name: Ajout du pointeur DNS sur le controleur de domaine wpsrvctldom1.uem.lan
hosts: DNS
gather_facts: no
roles:
- roles/DNS/
tags: DNS
- name: Ajout du mot de passe Keepass de l'utilisateur root de la machine
hosts: DNS
gather_facts: no
roles:
- roles/Keepass/
tags: keepass
I launch this playbook with this command :
ansible-playbook playbook/deployVM.yml --extra-vars "Host_Name=toto"
My variable is correctly interpreted in my tasks name but my third role which use the value of this variable to do operations on the appropriate host is skipped and Ansible says "skipping: no hosts matched
".
But when I re-launch my playbook with "--tags post_install
" to play only this role... It works !
I don't know why when I launch the entire playbook it doesn't work and when I launch just the 3rd role.. It works..
Can someone help me ?
Thx :)
PS : I add my Host_Name
machine into /etc/ansible/hosts
file thanks to the 2nd role :
[VM]
toto
ansible ansible-2.x
I've got a problem with my ansible playbook :
My playbook is composed of 5 roles and looks like this :
---
- name: Création de la machine virtuelle Host_Name à l'aide du template vcenter_template
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/deploy
tags: deploy
- name: Configuration de l'échange de clé de root@lrtstfpe vers root@ Host_Name
hosts: localhost
gather_facts: no
roles:
- roles/VMWare/pre_config
tags: pre_config
- name: Opérations post install
hosts: ' Host_Name '
gather_facts: no
roles:
- roles/VMWare/post_install
tags: post_install
- name: Ajout du pointeur DNS sur le controleur de domaine wpsrvctldom1.uem.lan
hosts: DNS
gather_facts: no
roles:
- roles/DNS/
tags: DNS
- name: Ajout du mot de passe Keepass de l'utilisateur root de la machine
hosts: DNS
gather_facts: no
roles:
- roles/Keepass/
tags: keepass
I launch this playbook with this command :
ansible-playbook playbook/deployVM.yml --extra-vars "Host_Name=toto"
My variable is correctly interpreted in my tasks name but my third role which use the value of this variable to do operations on the appropriate host is skipped and Ansible says "skipping: no hosts matched
".
But when I re-launch my playbook with "--tags post_install
" to play only this role... It works !
I don't know why when I launch the entire playbook it doesn't work and when I launch just the 3rd role.. It works..
Can someone help me ?
Thx :)
PS : I add my Host_Name
machine into /etc/ansible/hosts
file thanks to the 2nd role :
[VM]
toto
ansible ansible-2.x
ansible ansible-2.x
edited Nov 11 at 18:05
asked Nov 11 at 16:48
Wrest
105
105
"PS : I add my Host_Name machine into /etc/ansible/hosts file thanks to the 2nd role" does that mean before that 2nd role runs, thetoto
hostname isn't known to ansible? Because if so, I think you'll need to also useadd_host:
to teach the in-memory ansible about the host
– Matthew L Daniel
Nov 12 at 0:04
add a comment |
"PS : I add my Host_Name machine into /etc/ansible/hosts file thanks to the 2nd role" does that mean before that 2nd role runs, thetoto
hostname isn't known to ansible? Because if so, I think you'll need to also useadd_host:
to teach the in-memory ansible about the host
– Matthew L Daniel
Nov 12 at 0:04
"PS : I add my Host_Name machine into /etc/ansible/hosts file thanks to the 2nd role" does that mean before that 2nd role runs, the
toto
hostname isn't known to ansible? Because if so, I think you'll need to also use add_host:
to teach the in-memory ansible about the host– Matthew L Daniel
Nov 12 at 0:04
"PS : I add my Host_Name machine into /etc/ansible/hosts file thanks to the 2nd role" does that mean before that 2nd role runs, the
toto
hostname isn't known to ansible? Because if so, I think you'll need to also use add_host:
to teach the in-memory ansible about the host– Matthew L Daniel
Nov 12 at 0:04
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Ansible reads the /etc/ansible/hosts
or any other inventory file before starting the playbook. It is not read again during(or between) the plays. You are populating the hosts' file during the play and then trying to read in the next play; which will not work. You have to add the dynamically created host using add_host to playbook's in-memory inventory.
If you don't want to explicitly add_host
then there is another way to refresh inventory. You have to invoke meta module to refresh inventory before the play which requires the updated inventory.
Example:
- name: Re-read inventory files
meta: refresh_inventory
Thank you @Kanwar Saad, Your example solved my problem !
– Wrest
Nov 12 at 9:53
Glad that it helped .. can you accept my answer also
– Kanwar Saad
Nov 12 at 10:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Ansible reads the /etc/ansible/hosts
or any other inventory file before starting the playbook. It is not read again during(or between) the plays. You are populating the hosts' file during the play and then trying to read in the next play; which will not work. You have to add the dynamically created host using add_host to playbook's in-memory inventory.
If you don't want to explicitly add_host
then there is another way to refresh inventory. You have to invoke meta module to refresh inventory before the play which requires the updated inventory.
Example:
- name: Re-read inventory files
meta: refresh_inventory
Thank you @Kanwar Saad, Your example solved my problem !
– Wrest
Nov 12 at 9:53
Glad that it helped .. can you accept my answer also
– Kanwar Saad
Nov 12 at 10:03
add a comment |
up vote
0
down vote
accepted
Ansible reads the /etc/ansible/hosts
or any other inventory file before starting the playbook. It is not read again during(or between) the plays. You are populating the hosts' file during the play and then trying to read in the next play; which will not work. You have to add the dynamically created host using add_host to playbook's in-memory inventory.
If you don't want to explicitly add_host
then there is another way to refresh inventory. You have to invoke meta module to refresh inventory before the play which requires the updated inventory.
Example:
- name: Re-read inventory files
meta: refresh_inventory
Thank you @Kanwar Saad, Your example solved my problem !
– Wrest
Nov 12 at 9:53
Glad that it helped .. can you accept my answer also
– Kanwar Saad
Nov 12 at 10:03
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Ansible reads the /etc/ansible/hosts
or any other inventory file before starting the playbook. It is not read again during(or between) the plays. You are populating the hosts' file during the play and then trying to read in the next play; which will not work. You have to add the dynamically created host using add_host to playbook's in-memory inventory.
If you don't want to explicitly add_host
then there is another way to refresh inventory. You have to invoke meta module to refresh inventory before the play which requires the updated inventory.
Example:
- name: Re-read inventory files
meta: refresh_inventory
Ansible reads the /etc/ansible/hosts
or any other inventory file before starting the playbook. It is not read again during(or between) the plays. You are populating the hosts' file during the play and then trying to read in the next play; which will not work. You have to add the dynamically created host using add_host to playbook's in-memory inventory.
If you don't want to explicitly add_host
then there is another way to refresh inventory. You have to invoke meta module to refresh inventory before the play which requires the updated inventory.
Example:
- name: Re-read inventory files
meta: refresh_inventory
answered Nov 12 at 8:10
Kanwar Saad
99811122
99811122
Thank you @Kanwar Saad, Your example solved my problem !
– Wrest
Nov 12 at 9:53
Glad that it helped .. can you accept my answer also
– Kanwar Saad
Nov 12 at 10:03
add a comment |
Thank you @Kanwar Saad, Your example solved my problem !
– Wrest
Nov 12 at 9:53
Glad that it helped .. can you accept my answer also
– Kanwar Saad
Nov 12 at 10:03
Thank you @Kanwar Saad, Your example solved my problem !
– Wrest
Nov 12 at 9:53
Thank you @Kanwar Saad, Your example solved my problem !
– Wrest
Nov 12 at 9:53
Glad that it helped .. can you accept my answer also
– Kanwar Saad
Nov 12 at 10:03
Glad that it helped .. can you accept my answer also
– Kanwar Saad
Nov 12 at 10:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250952%2fset-hosts-value-with-an-extra-vars-doesnt-work-for-my-ansible-role%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"PS : I add my Host_Name machine into /etc/ansible/hosts file thanks to the 2nd role" does that mean before that 2nd role runs, the
toto
hostname isn't known to ansible? Because if so, I think you'll need to also useadd_host:
to teach the in-memory ansible about the host– Matthew L Daniel
Nov 12 at 0:04