Ansible playbook tips

Ansible playbook tips

Checks :

if a file is present

- name: Check if we got the generate_report file in /etc/cron.d/ folder
path: /etc/cron.d/generate_report
register: set_DI_status
become: yes
become_method: sudo
become_flags: -i
failed_when: set_DI_status.stat.exists == false


Make a playbook executable like a shell script

To make a playbook executable, just add ansible-playbook as a shebang.

- name: My playbook title

And make it executable with chmod +x myPlayBook.yml

Prevent warning

Prevent the warning:

[WARNING]: Platform linux on host yourHost is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter
could change this. See for more information.

just add ansible_python_interpreter: /usr/bin/python3 to your script:

- hosts: your_specific_host
ansible_python_interpreter: /usr/bin/python3 # Replace with your version.

# Your tasks go here...