Get the pid of a running playbook for use within the playbook

前端 未结 5 1748
终归单人心
终归单人心 2021-01-17 14:35

When we run a playbook, with verbose output enabled, in the ansible logs we can see something like this:

2016-02-03 12:51:58,235 p=4105 u=root | PLAY RECAP

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-17 15:16

    You can define the PID for localhost using the set_fact module with a lookup filter.

    - hosts: localhost
      tasks:
        - set_fact:
            pid: "{{ lookup('pipe', 'echo $PPID') }}"
    

    And later on you can reference the PID via the hostvars dictionary.

    - hosts: remote
      tasks:
        - debug: var=hostvars.localhost.pid
    

提交回复
热议问题