I want to print result in ansible-playbook
but not working.
python script:
#!/usr/bin/python3import timewhile True:print("I'm alive")time.sleep(5)
deploy_python_script.yml:
connection: localbecome: truevars:python_script_src: /home/ubuntu/scripts/python_script.pypython_script_dest: /opt/web_service/python_script.pypython_script_mode: "0755"python_interpreter: /usr/bin/python3tasks:- name: Ensure destination directory existsfile:path: /opt/web_servicestate: directorymode: "0755"- name: Copy Python script to servercopy:src: "{{ python_script_src }}"dest: "{{ python_script_dest }}"mode: "{{ python_script_mode }}"- name: Run the scriptcommand: "{{ python_interpreter }} {{ python_script_dest }}"register: script_resultbecome: truebecome_user: root- name: Check if script randebug:msg: "Script ran: {{ script_output.changed }}"- name: Show outputdebug:var: script_result
I ran the following command:
ansible-playbook -i localhost -vvv deploy_python_script.yml
result:
TASK \[Run the script\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*task path: /home/ubuntu/ansible/deploy_python_scriptt.yml:27\<127.0.0.1\> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu\<127.0.0.1\> EXEC /bin/sh -c 'echo \~ubuntu && sleep 0'\<127.0.0.1\> EXEC /bin/sh -c '( umask 77 && mkdir -p "\` echo /home/ubuntu/.ansible/tmp \`"&& mkdir "\` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1709641109.322795-17936-40556479292100 \`" && echo ansible-tmp-1709641109.322795-17936-40556479292100="\` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1709641109.322795-17936-40556479292100 \`" ) && sleep 0'Using module file /usr/lib/python3/dist-packages/ansible/modules/command.py\<127.0.0.1\> PUT /home/ubuntu/.ansible/tmp/ansible-local-17791bx4xmv_v/tmplblg_5p8 TO /home/ubuntu/.ansible/tmp/ansible-tmp-1709641109.322795-17936-40556479292100/AnsiballZ_command.py\<127.0.0.1\> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1709641109.322795-17936-40556479292100/ /home/ubuntu/.ansible/tmp/ansible-tmp-1709641109.322795-17936-40556479292100/AnsiballZ_command.py && sleep 0'\<127.0.0.1\> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-fqbwhdiehqpybtbtjwcnrafqdjqdbfbf ; /usr/bin/python3 /home/ubuntu/.ansible/tmp/ansible-tmp-1709641109.322795-17936-40556479292100/AnsiballZ_command.py'"'"' && sleep 0