Skip to content

Instantly share code, notes, and snippets.

@steenzout
Last active September 19, 2016 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steenzout/69647371458c7e15a775 to your computer and use it in GitHub Desktop.
Save steenzout/69647371458c7e15a775 to your computer and use it in GitHub Desktop.
Compilation of ansible tasks useful to setup testing.
- name: is X package installed?
command: dpkg-query -W -f='${Status}\n' X
register: test
changed_when: no
failed_when: test.stdout.find('install ok installed') == -1
- name: file is present?
command: test -e path_to_file
changed_when: no
- name: file content contains X?
command: grep 'X' path_to_file
changed_when: no
- name: directory(ies) are present?
command: "test -d {{ item }}"
with_items:
- /home/ubuntu
changed_when: no
- name: file content contains line X?
command: grep '^X$' path_to_file
changed_when: no
- name: user(s) are present?
command: "getent passwd {{ item }}"
with_items:
- ubuntu
changed_when: no
- name: is command installed?
shell: which command
changed_when: no
- name: verify command version
shell: command --version
register: test
changed_when: no
failed_when: test is defined and test.stdout.find("command {{ command_version }} from") == -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment