Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Last active December 8, 2021 07:15
Show Gist options
  • Save muxueqz/c0802e7a78984f9fec267040ae6bf0eb to your computer and use it in GitHub Desktop.
Save muxueqz/c0802e7a78984f9fec267040ae6bf0eb to your computer and use it in GitHub Desktop.
- hosts: all
tasks:
- name: Create temporary file
ansible.builtin.tempfile:
state: file
suffix: temp
register: tempfile_1
- name: Use the registered var and the file module to remove the temporary file
ansible.builtin.file:
path: "{{ tempfile_1.path }}"
state: absent
when: tempfile_1.path is defined
- name: Ansible create file with content example
copy:
dest: "{{ tempfile_1.path }}"
content: |
import sys
import json
# print(sys.version)
# print(json.dumps(sys.version))
if sys.platform == 'linux':
print('You are a good machine')
else:
print('You are a bad machine')
when: tempfile_1.path is defined
- name: Exec python
# shell:
command:
python3 "{{ tempfile_1.path }}"
# uptime
args:
removes: "{{ tempfile_1.path }}"
when: tempfile_1.path is defined
- name: python shell
shell: |
import sys
import json
# print(sys.version)
# print(json.dumps(sys.version))
if sys.platform == 'linux':
print('You are a good machine')
else:
print('You are a bad machine')
args:
executable: /usr/bin/python3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment