Skip to content

Instantly share code, notes, and snippets.

@bertvv
Last active August 29, 2015 14:20
Show Gist options
  • Save bertvv/8883f7c215560763b5c3 to your computer and use it in GitHub Desktop.
Save bertvv/8883f7c215560763b5c3 to your computer and use it in GitHub Desktop.
Test for changes in validation output in Ansible

Test for new implementation of validation error output in:

Run with

ansible-playbook -i inventory test.yml --skip-tags=fail

Tests that should fail are tagged as such. Leave the --skip-tags to let them fail...

File contents for test fixture:

  • inventory:
    localhost
    
  • a/testcopysucceed.txt:
    This is a test
    
  • a/testcopyfail.txt:
    This will fail
    
  • a/template.j2:
    {{ ansible_hostname }}
    

Directory b/ should contain two empty files, b/lineinfilenovalidation.txt and b/lineinfile.txt.

---
- hosts: all
tasks:
- name: Test copy without validation
copy: src='a/testcopysucceed.txt' dest='b/testcopysucceednovalidation.txt'
- name: Test copy success
copy: src='a/testcopysucceed.txt' dest='b/testcopysucceed.txt' validate='grep -L test %s'
- name: Test copy failure
copy: src='a/testcopyfail.txt' dest='b/testcopyfail.txt' validate='grep -L test %s'
tags: fail
- name: Test invalid validation command
copy: src='a/testcopyfail.txt' dest='b/testcopyfail.txt' validate='grep -L test'
tags: fail
- name: Test lineinfile without validation
lineinfile: dest='b/lineinfilenovalidation.txt' regexp='^LINEINFILE$' line='LINEINFILE'
- name: Test lineinfile success
lineinfile: dest='b/lineinfilenovalidation.txt' regexp='^LINEINFILE$' line='LINEINFILE' validate='grep -L LINE %s'
- name: Test lineinfile failure
lineinfile: dest='b/lineinfile.txt' regexp='^LINEINFILE$' line='LINEINFILE' validate='grep -L POINT %s'
tags: fail
- name: Test template success
template: src='a/template.j2' dest='b/template.txt' validate='grep -L {{ ansible_hostname }} %s'
- name: Test template failure
template: src='a/template.j2' dest='b/templatefail.txt' validate='grep -L FOO %s'
tags: fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment