/test/integration/roles/test_template/tasks/main.yml

https://github.com/ajanthanm/ansible · YAML · 66 lines · 36 code · 12 blank · 18 comment · 0 complexity · df3f1689bfad05ef21c72e828905c45a MD5 · raw file

  1. # test code for the template module
  2. # (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
  3. # This file is part of Ansible
  4. #
  5. # Ansible is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # Ansible is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
  17. - name: fill in a basic template
  18. template: src=foo.j2 dest={{output_dir}}/foo.templated mode=0644
  19. register: template_result
  20. - assert:
  21. that:
  22. - "'changed' in template_result"
  23. - "'dest' in template_result"
  24. - "'group' in template_result"
  25. - "'gid' in template_result"
  26. - "'md5sum' in template_result"
  27. - "'owner' in template_result"
  28. - "'size' in template_result"
  29. - "'src' in template_result"
  30. - "'state' in template_result"
  31. - "'uid' in template_result"
  32. - name: verify that the file was marked as changed
  33. assert:
  34. that:
  35. - "template_result.changed == true"
  36. # VERIFY CONTENTS
  37. - name: copy known good into place
  38. copy: src=foo.txt dest={{output_dir}}/foo.txt
  39. - name: compare templated file to known good
  40. shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt
  41. register: diff_result
  42. - name: verify templated file matches known good
  43. assert:
  44. that:
  45. - 'diff_result.stdout == ""'
  46. - "diff_result.rc == 0"
  47. # VERIFY MODE
  48. - name: set file mode
  49. file: path={{output_dir}}/foo.templated mode=0644
  50. register: file_result
  51. - name: ensure file mode did not change
  52. assert:
  53. that:
  54. - "file_result.changed != True"