On Saturday, 17 February 2018 06.00.53 CET David Fazeli wrote:
> 
> please explain me. How can I access to answer one prompt on another server? 
> my 
> hosts:
> 
> [dbs]
> db1
> db2
> db3
> 
> I have one role and mytasks/main.yml is:
> 
> - pause:
>    prompt: "Do you want to install mysql (yes/no)?"
>   register: install_mysql
> 
> - include_tasks: mysql.yml
>   when: install_mysql.user_input | bool
> 
> when I execute this role, only first server skip toMySQL.yml another server 
> execute.MySQL.yml

pause is only run on the first host and only that host get the variable 
registered.
So the include task should have failed for db2 and db3 since they not have this 
variable set unless you are reusing install_mysql.



> Also, I check this method :
> 
>   ---
>    - pause:
>        prompt: "Do you want to install mysql (yes/no)?"
>       register: install_mysql
>       delegate_to: localhost
> 
> - include_tasks: mysql.yml
>   when: hostvars['localhost']['install_mysql']['user_input'] == 'yes'
> 
> but The same output becomes.

Delegate_to does run the task on another host, but the variable is still 
registered on the original host(the first host).
Pause doesn't support delegate_facts so you need to do this

  - pause:
      prompt: "Do you want to install mysql (yes/no)?"
    register: install_mysql

  - include_tasks: mysql.yml
    when: hostvars[ansible_play_hosts | first].install_mysql.user_input | bool

 
-- 
Kai Stian Olstad

-- 
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/4202779.GOSlk6istW%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply via email to