Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
Get the pid of a running playbook for use within the playbook

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

I guess that the p=4105 is the pid of the playbook when it ran.

Is there a way to get this pid inside the playbook during its runtime (as a variable for example)?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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
over 4 years ago · Santiago Trujillo Relatório

0

This sounds a little like an XY problem, but one option may be to spawn a shell with the shell command and then ask for the parent PID:

- name: get pid of playbook
  shell: |
    echo "$PPID"
  register: playbook_pid

This will give you the PID of the python process that is executing the playbook.

over 4 years ago · Santiago Trujillo Relatório

0

This might be what you are looking for, but is only applicable to Linux:

- name: Get the pid of this playbook
  shell: pstree -spal $PPID | grep ansible-playbook | awk '{print $1;exit}' | awk -F, '{print $2}'
  register: ansible_pid

- name: Set the ansible playbook pid variable
  set_fact:
    ansible_playbook_pid: "{{ ansible_pid.stdout|int }}"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda