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

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

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

Greetings !

Hello Ansible team,

Can anyone look into this?