Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible to display python script prints

Tags:

python

ansible

I am executing python script through ansible. I have some prints in python but none seem to display in the Ansible output. I see following in the output of the Ansible.

{"changed": true, "rc": 0, "stderr": "", "stdout": "", "stdout_lines": []}

I have tried the following to display the prints in ansible.

tasks:   
  - name: Run script on remote host
    script: python_script.py 
    register: output

  - debug: var=output.stdout_lines

But see that none of the prints are being displayed.

ok: [remoteHostName] => {
    "output.stdout_lines": []

I am new to Ansible. Any references or guidance would help me print the log from python script.

like image 203
siri Avatar asked Apr 14 '26 17:04

siri


1 Answers

Your Ansible code is fine. See below. You should check the output of your script python_script.py.

  tasks:
    - script: python_script.py
      register: output
    - debug: var=output.stdout_lines


> cat python_script.py 
#!/usr/bin/python
print("Hello World!")

> ansible-playbook test-10.yml
[...]
TASK [debug] ******************************************
ok: [localhost] => {
    "output.stdout_lines": [
        "Hello World!"
    ]
}
like image 73
Vladimir Botka Avatar answered Apr 17 '26 06:04

Vladimir Botka