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.
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!"
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With