S
S
speedvm2019-01-15 18:01:06
Ansible
speedvm, 2019-01-15 18:01:06

How to parse stdout output word by word in ansible?

Good day!
There is an ansible task that launches a container in Proxmox:

- name: Запуск контейнера
  proxmox:
    hostname: tmp0
    api_user: [email protected]
    api_password: root
    api_host: 192.168.254.23
    state: started

Its output is the following (if run with the -v switch):
msg: VM 106 started
After starting the container, I need to know its ID, which is indicated in the output of the previous task.
How to parse the task output and save it to a variable?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Shitskov, 2019-01-15
@speedvm

Try like this

- name: Запуск контейнера
proxmox:
hostname: tmp0
api_user: [email protected]
api_password: root
api_host: 192.168.254.23
state: started
register: result

- name: Debug registered var
debug: {{  result.stdout_lines.split()[1] }}

D
Dmitry, 2019-01-15
@q2digger

Have you tried it like this?
- name: Start
proxmox container:
hostname: tmp0
api_user: [email protected]
api_password: root
api_host: 192.168.254.23
state: started
register: result
- name: Debug registered var
debug: var=result.stdout_lines

P
Puma Thailand, 2019-01-15
@opium

Do not do this, just set the ID yourself when creating

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question