Last active
October 1, 2020 13:45
-
-
Save zeitounator/314ed09b31a6d75bc99e415a98426740 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
gather_facts: false | |
vars: | |
my_python_script_content: |- | |
import sys | |
sys.stdout.write('test') | |
tasks: | |
- name: create my python script right for this example | |
copy: | |
dest: /tmp/test_script.py | |
content: "{{ my_python_script_content }}" | |
- name: run my script, register result | |
script: /tmp/test_script.py | |
args: | |
executable: python3 | |
register: run_script | |
- name: Show raw registered var | |
debug: | |
var: run_script | |
- name: Eventually assign the exact result to a relevant var | |
set_fact: | |
my_specific_var: "{{ run_script.stdout }}" | |
- name: Use that var in whatever task | |
debug: | |
msg: "My wonderful python script has returned the following result: {{ my_specific_var }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ansible-playbook 0-playbook.yml | |
PLAY [localhost] **************************************************************************************************************************************************************************************************************************** | |
TASK [create my python script right for this example] ************************************************************************************************************************************************************************************************************** | |
changed: [localhost] | |
TASK [run my script, register result] ******************************************************************************************************************************************************************************************************* | |
changed: [localhost] | |
TASK [Show raw registered var] ************************************************************************************************************************************************************************************************************** | |
ok: [localhost] => { | |
"run_script": { | |
"changed": true, | |
"failed": false, | |
"rc": 0, | |
"stderr": "", | |
"stderr_lines": [], | |
"stdout": "test", | |
"stdout_lines": [ | |
"test" | |
] | |
} | |
} | |
TASK [Eventually assign the exact result to a relevant var] ********************************************************************************************************************************************************************************* | |
ok: [localhost] | |
TASK [Use that var in whatever task] ******************************************************************************************************************************************************************************************************** | |
ok: [localhost] => { | |
"msg": "My wonderful python script has returned the following result: test" | |
} | |
PLAY RECAP ********************************************************************************************************************************************************************************************************************************** | |
localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment