# skip some task with prompt in ansible

**URL:** <https://forum.ansible.com/t/skip-some-task-with-prompt-in-ansible/26769>\
**Category:** Ansible Project\
**Created:** [February 17, 2018, 5:00am UTC](https://forum.ansible.com/t/skip-some-task-with-prompt-in-ansible/26769 "2018-02-17T05:00:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Fazeli](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@David\_Fazeli](https://forum.ansible.com/u/David_Fazeli)\
**Post date:** [February 17, 2018, 5:00am UTC](https://forum.ansible.com/t/skip-some-task-with-prompt-in-ansible/26769/1 "2018-02-17T05:00:53Z")

</div>

please explain me. How can I access to answer one prompt on another server? `my hosts`:

```auto
[dbs]
db1
db2
db3

```

I have one role and my`tasks/main.yml` is:

```auto
- 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 to`MySQL.yml` another server execute.`MySQL.yml`

I want if the user enters for`no` answer prompt,‍‍`MySQL.yml` does not execute for any server. but when I enter no It will be installed again!!

```auto
 [root@anisble ansible]# ansible-playbook playbooks/test.yml 
PLAY [dbs] 
**************************************************************
    TASK [Gathering Facts] 
*******************
ok: [db1]
ok: [db3]
ok: [db2]
TASK [ssh : pause]
 ********************************************************************************
[ssh : pause]
Do you want to install mysql (yes/no)?:
no
ok: [db1]
TASK [ssh : include_tasks]
 ********************************************************************************
skipping: [db1]
included: /etc/ansible/roles/ssh/tasks/mysql.yml for db2, db3
TASK [ssh : install mysql]
 ********************************************************************************
ok: [db3]
ok: [db2]
PLAY RECAP 
********************************************************************************
db1 : ok=2 changed=0 unreachable=0 failed=0   
db2 : ok=3 changed=0 unreachable=0 failed=0   
db3 : ok=3 changed=0 unreachable=0 failed=0   

```

Also, I check this method :

```auto
  ---
   - 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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 17, 2018, 9:04am UTC](https://forum.ansible.com/t/skip-some-task-with-prompt-in-ansible/26769/2 "2018-02-17T09:04:29Z")

</div>

> 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:  
> &nbsp;&nbsp;&nbsp;prompt: "Do you want to install mysql (yes/no)?"  
> &nbsp;&nbsp;register: install\_mysql
> 
> - include\_tasks: mysql.yml  
> &nbsp;&nbsp;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 :
> 
> &nbsp;&nbsp;---  
> &nbsp;&nbsp;&nbsp;- pause:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt: "Do you want to install mysql (yes/no)?"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: install\_mysql  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost
> 
> - include\_tasks: mysql.yml  
> &nbsp;&nbsp;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

&nbsp;&nbsp;- pause:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt: "Do you want to install mysql (yes/no)?"  
&nbsp;&nbsp;&nbsp;&nbsp;register: install\_mysql

&nbsp;&nbsp;- include\_tasks: mysql.yml  
&nbsp;&nbsp;&nbsp;&nbsp;when: hostvars[ansible\_play\_hosts | first].install\_mysql.user\_input | bool
