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

11 views
Skip to first unread message

Kunalsing Thakur

unread,
May 22, 2019, 7:07:30 AM5/22/19
to Ansible Project
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


Kunalsing Thakur

unread,
May 22, 2019, 7:22:16 AM5/22/19
to Ansible Project
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

Kunalsing Thakur

unread,
May 23, 2019, 6:12:45 AM5/23/19
to Ansible Project
Greetings !

Hello Ansible team,

Can anyone look into this?


On Wednesday, May 22, 2019 at 4:37:30 PM UTC+5:30, Kunalsing Thakur wrote:
Reply all
Reply to author
Forward
0 new messages