Ansible Cheatsheet

If File Exists

- stat: path="my_file"
  register: my_file

- name: A command
  a_command
  when: my_file.stat.exists == True

Conditional Based on the Contents of a File

- shell: cat "my_file"
  register: my_file_contents
  

- another_command: xyz
  when: my_file_contents.stdout.find('the target text') != -1

Skipping Failed Commands

- name: this will not be counted as a failure
  command: /bin/false
  ignore_errors: yes
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s