# need to perform action on localhost in multiple host action of playbooks

**URL:** <https://forum.ansible.com/t/need-to-perform-action-on-localhost-in-multiple-host-action-of-playbooks/30396>\
**Category:** Ansible Project\
**Created:** [May 22, 2019, 11:07am UTC](https://forum.ansible.com/t/need-to-perform-action-on-localhost-in-multiple-host-action-of-playbooks/30396 "2019-05-22T11:07:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [May 22, 2019, 11:07am UTC](https://forum.ansible.com/t/need-to-perform-action-on-localhost-in-multiple-host-action-of-playbooks/30396/1 "2019-05-22T11:07:30Z")

</div>

Hello Ansible Team,

I need to run playbook on host when puppet run done on node and then it will immediately restore the snapshot. and again it will run puppet. can we pass the control to task when second task is completed it will move to first one

- hosts: node1, node2, node3  
vars\_files:

- /etc/ansible/inventories/group\_vars/common.yaml  
serial: 1  
gather\_facts: false  
any\_errors\_fatal: true  
tasks:

- name: run puppet  
shell: puppet agent -tdv

- hosts: localhost  
vars\_files:

- /etc/ansible/inventories/group\_vars/common.yaml  
serial: 1  
gather\_facts: false  
tasks:

- set\_fact:  
vm\_name: “{{ ansible\_ssh\_host }}”

- name: Revert snapshot  
vmware\_guest\_snapshot:  
hostname: “{{ vcenter\_server }}”  
username: “{{ vcenter\_user }}”  
password: “{{ vcenter\_pass }}”  
datacenter: “example”  
folder: “/example/vm”  
name: “{{ vm\_name}}”  
state: revert  
validate\_certs: False  
snapshot\_name: original  
delegate\_to: localhost

- name: Set the state of a virtual machine to poweron  
vmware\_guest\_powerstate:  
hostname: “{{ vcenter\_server }}”  
username: “{{ vcenter\_user }}”  
password: “{{ vcenter\_pass }}”  
validate\_certs: False  
name: “{{ vm\_name }}”  
state: powered-on  
delegate\_to: localhost

- name: Wait for the reboot to complete if there was a change.  
wait\_for\_connection:  
connect\_timeout: 10  
sleep: 5  
delay: 5  
timeout: 300

- name: checking machine up and running  
shell: uptime

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [May 22, 2019, 11:22am UTC](https://forum.ansible.com/t/need-to-perform-action-on-localhost-in-multiple-host-action-of-playbooks/30396/2 "2019-05-22T11:22:16Z")

</div>

i tried to seprate another playbook and include like post\_tasks but thats not worked.

- hosts: node1, node2, node3  
vars\_files:
- /etc/ansible/inventories/group\_vars/common.yaml  
serial: 1  
gather\_facts: false  
any\_errors\_fatal: true  
tasks:
- name: run puppet  
shell: puppet agent -tdv  
post\_tasks:
- include: vmware\_snapshot\_revert.yaml

But its not worked because we are calling this playbook from remote node which is not possible. so how to handle this situtation

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [May 23, 2019, 10:12am UTC](https://forum.ansible.com/t/need-to-perform-action-on-localhost-in-multiple-host-action-of-playbooks/30396/3 "2019-05-23T10:12:44Z")

</div>

Greetings !

Hello Ansible team,

Can anyone look into this?
