Rename tests to test, use old directory name.

This commit is contained in:
Michael DeHaan 2014-02-20 19:11:15 -05:00
commit 2177b773c8
132 changed files with 0 additions and 0 deletions

14
test/integration/Makefile Normal file
View file

@ -0,0 +1,14 @@
all: non_destructive destructive check_mode test_hash # amazon rackspace
non_destructive:
ansible-playbook non_destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS)
destructive:
ansible-playbook destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS)
check_mode:
ansible-playbook check_mode.yml -i inventory -e @integration_config.yml -v --check $(TEST_FLAGS)
test_hash:
ANSIBLE_HASH_BEHAVIOUR=replace ansible-playbook test_hash.yml -i inventory -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}'
ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook test_hash.yml -i inventory -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}'

View file

@ -0,0 +1,57 @@
Integration tests
=================
The ansible integration system.
Tests for playbooks, by playbooks.
Some tests may require cloud credentials.
Tests should be run as root.
Configuration
=============
Making your own version of integration_config.yml can allow for setting some tunable parameters to help run
the tests better in your environment.
Prerequisites
=============
The tests will assume things like hg, svn, and git are installed and in path.
(Complete list pending)
Non-destructive Tests
=====================
These tests will modify files in subdirectories, but will not do things that install or remove packages or things
outside of those test subdirectories. They will also not reconfigure or bounce system services.
Run as follows:
make non_destructive
You can select specific tests with the --tags parameter.
TEST_FLAGS="--tags test_vars_blending" make
Destructive Tests
=================
These tests are allowed to install and remove some trivial packages. You will likely want to devote these
to a virtual environment. They won't reformat your filesystem, however :)
make destructive
Cloud Tests
===========
Details pending, but these require cloud credentials. These are not 'tests run in the cloud' so much as tests
that leverage the cloud modules and are organized by cloud provider.
Instructions
============
Pending

6
test/integration/all.yml Normal file
View file

@ -0,0 +1,6 @@
- include: test_setup.yml
- include: non_destructive.yml
- include: destructive.yml
- include: rackspace.yml
- include: amazon.yml

View file

@ -0,0 +1,4 @@
- hosts: testhost
gather_facts: True
roles: []

View file

@ -0,0 +1,3 @@
- hosts: testhost
roles:
- { role: test_always_run, tags: test_always_run }

View file

@ -0,0 +1,9 @@
- hosts: testhost
gather_facts: True
roles:
- { role: test_service, tags: test_service }
- { role: test_pip, tags: test_pip }
- { role: test_gem, tags: test_gem }
- { role: test_yum, tags: test_yum }
- { role: test_apt, tags: test_apt }

View file

@ -0,0 +1,17 @@
a: 999
b: 998
c: 997
d: 996
uno: 1
dos: 2
tres: 3
etest: 'from group_vars'
inventory_beats_default: 'narf'
# variables used for hash merging behavior testing
test_hash:
group_vars_all: "this is in group_vars/all"
# variables used for conditional testing
test_bare: true
test_bare_var: 123
test_bare_nested_good: "{{test_bare_var}} == 123"
test_bare_nested_bad: "{{test_bare_var}} == 321"

View file

@ -0,0 +1,3 @@
tres: 'three'
hash_test:
group_vars_local: "this is in group_vars/local"

View file

@ -0,0 +1,7 @@
a: 1
b: 2
c: 3
d: 4
role_var_beats_inventory: 'should_not_see_this'
test_hash:
host_vars_testhost: "this is in host_vars/testhost"

View file

@ -0,0 +1,9 @@
---
output_dir: ~/ansible_testing
non_root_test_user: ansible
pip_test_package: epdb
# variables used in precedence tests, here passed to -e
etest: 'from -e'

View file

@ -0,0 +1,27 @@
[local]
testhost ansible_ssh_host=127.0.0.1 ansible_connection=local
testhost2 ansible_ssh_host=127.0.0.1 ansible_connection=local
# the following inline declarations are accompanied
# by (preferred) group_vars/ and host_vars/ variables
# and are used in testing of variable precedence
[arbitrary_parent:children]
local
[local:vars]
parent_var=6000
groups_tree_var=5000
[arbitrary_parent:vars]
groups_tree_var=4000
overridden_in_parent=1000
[arbitrary_grandparent:children]
arbitrary_parent
[arbitrary_grandparent:vars]
groups_tree_var=3000
grandparent_var=2000
overridden_in_parent=2000

View file

@ -0,0 +1,31 @@
- hosts: testhost
# these variables are defined here for variable blending tests only.
# in general, define test variables in the role/rolenamevars/main.yml
vars_files:
- vars_file.yml
vars:
vars_var: 123
gather_facts: True
roles:
- { role: test_ping, tags: test_ping }
- { role: test_copy, tags: test_copy }
- { role: test_stat, tags: test_stat }
- { role: test_template, tags: test_template }
- { role: test_file, tags: test_file }
- { role: test_fetch, tags: test_fetch }
- { role: test_synchronize, tags: test_synchronize }
- { role: test_subversion, tags: test_subversion }
- { role: test_git, tags: test_git }
- { role: test_hg, tags: test_hg }
- { role: test_changed_when, tags: test_changed_when }
- { role: test_var_blending, parameterized_beats_default: 1234, tags: test_var_blending }
- { role: test_lineinfile, tags: test_lineinfile }
- { role: test_ignore_errors, tags: test_ignore_errors }
- { role: test_unarchive, tags: test_unarchive }
- { role: test_filters, tags: test_filters }
- { role: test_facts_d, tags: test_facts_d }
- { role: test_conditionals, tags: test_conditionals }

View file

@ -0,0 +1,4 @@
- hosts: testhost
gather_facts: True
roles: []

View file

@ -0,0 +1,29 @@
# test code for the copy module and action plugin
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: clean out the test directory
file: name={{output_dir|mandatory}} state=absent
tags:
- prepare
- name: create the test directory
file: name={{output_dir}} state=directory
tags:
- prepare

View file

@ -0,0 +1,18 @@
# test code for the always_run option
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,29 @@
# test code for the always_run option
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: run a command while in check mode
shell: echo "running"
always_run: yes
register: result
- name: assert that the command was run
assert:
that:
- "result.changed == true"
- "result.stdout == 'running'"
- "result.rc == 0"

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,69 @@
# UNINSTALL
- name: uninstall wget with apt
apt: pkg=wget state=absent purge=yes
register: apt_result
- name: check wget with dpkg
shell: dpkg --get-selections | fgrep wget
failed_when: False
register: dpkg_result
- debug: var=apt_result
- debug: var=dpkg_result
- name: verify uninstallation of wget
assert:
that:
- "'changed' in apt_result"
- "dpkg_result.rc == 1"
# UNINSTALL AGAIN
- name: uninstall wget with apt
apt: pkg=wget state=absent purge=yes
register: apt_result
- name: verify no change on re-uninstall
assert:
that:
- "not apt_result.changed"
# INSTALL
- name: install wget with apt
apt: name=wget state=present
register: apt_result
- name: check wget with dpkg
shell: dpkg --get-selections | fgrep wget
failed_when: False
register: dpkg_result
- debug: var=apt_result
- debug: var=dpkg_result
- name: verify installation of wget
assert:
that:
- "apt_result.changed"
- "dpkg_result.rc == 0"
- name: verify apt module outputs
assert:
that:
- "'invocation' in apt_result"
- "'changed' in apt_result"
- "'item' in apt_result"
- "'stderr' in apt_result"
- "'stdout' in apt_result"
- "'stdout_lines' in apt_result"
# INSTALL AGAIN
- name: install wget with apt
apt: name=wget state=present
register: apt_result
- name: verify no change on re-install
assert:
that:
- "not apt_result.changed"

View file

@ -0,0 +1,21 @@
# test code for the yum module
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- include: 'apt.yml'
when: ansible_distribution in ('Ubuntu', 'Debian')

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,42 @@
# test code for the changed_when parameter
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: ensure shell is always changed
shell: ls -al /tmp
register: shell_result
- debug: var=shell_result
- name: changed should always be true for shell
assert:
that:
- "shell_result.changed"
- name: test changed_when override for shell
shell: ls -al /tmp
changed_when: False
register: shell_result
- debug: var=shell_result
- name: changed should be false
assert:
that:
- "not shell_result.changed"

View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo -n "win"

View file

@ -0,0 +1,195 @@
# test code for conditional statements
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: test conditional '=='
shell: echo 'testing'
when: 1 == 1
register: result
- name: assert conditional '==' ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test bad conditional '=='
shell: echo 'testing'
when: 0 == 1
register: result
- name: assert bad conditional '==' did NOT run
assert:
that:
- "result.skipped == true"
- name: test conditional '!='
shell: echo 'testing'
when: 0 != 1
register: result
- name: assert conditional '!=' ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test bad conditional '!='
shell: echo 'testing'
when: 1 != 1
register: result
- name: assert bad conditional '!=' did NOT run
assert:
that:
- "result.skipped == true"
- name: test conditional 'in'
shell: echo 'testing'
when: 1 in [1,2,3]
register: result
- name: assert conditional 'in' ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test bad conditional 'in'
shell: echo 'testing'
when: 1 in [7,8,9]
register: result
- name: assert bad conditional 'in' did NOT run
assert:
that:
- "result.skipped == true"
- name: test conditional 'not in'
shell: echo 'testing'
when: 0 not in [1,2,3]
register: result
- name: assert conditional 'not in' ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test bad conditional 'not in'
shell: echo 'testing'
when: 1 not in [1,2,3]
register: result
- name: assert bad conditional 'not in' did NOT run
assert:
that:
- "result.skipped == true"
- name: test conditional 'is defined'
shell: echo 'testing'
when: test_bare is defined
register: result
- name: assert conditional 'is defined' ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test bad conditional 'is defined'
shell: echo 'testing'
when: foo_asdf_xyz is defined
register: result
- name: assert bad conditional 'is defined' did NOT run
assert:
that:
- "result.skipped == true"
- name: test conditional 'is not defined'
shell: echo 'testing'
when: foo_asdf_xyz is not defined
register: result
- name: assert conditional 'is not defined' ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test bad conditional 'is not defined'
shell: echo 'testing'
when: test_bare is not defined
register: result
- name: assert bad conditional 'is not defined' did NOT run
assert:
that:
- "result.skipped == true"
- name: test bare conditional
shell: echo 'testing'
when: test_bare
register: result
- name: assert bare conditional ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test conditional using a variable
shell: echo 'testing'
when: test_bare_var == 123
register: result
- name: assert conditional using a variable ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test good conditional based on nested variables
shell: echo 'testing'
when: test_bare_nested_good
register: result
- name: assert good conditional based on nested var ran
assert:
that:
- "result.changed == true"
- "result.stdout == 'testing'"
- "result.rc == 0"
- name: test bad conditional based on nested variables
shell: echo 'testing'
when: test_bare_nested_bad
register: result
- name: assert that the bad nested conditional did NOT run
assert:
that:
- "result.skipped == true"

View file

@ -0,0 +1 @@
foo.txt

View file

@ -0,0 +1 @@
baz

View file

@ -0,0 +1 @@
baz

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,134 @@
# test code for the copy module and action plugin
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: record the output directory
set_fact: output_file={{output_dir}}/foo.txt
- name: initiate a basic copy, and also test the mode
copy: src=foo.txt dest={{output_file}} mode=0444
register: copy_result
- name: check the mode of the output file
file: name={{output_file}} state=file
register: file_result_check
- name: assert the mode is correct
assert:
that:
- "file_result_check.mode == '0444'"
- name: assert basic copy worked
assert:
that:
- "'changed' in copy_result"
- "'dest' in copy_result"
- "'group' in copy_result"
- "'gid' in copy_result"
- "'md5sum' in copy_result"
- "'owner' in copy_result"
- "'size' in copy_result"
- "'src' in copy_result"
- "'state' in copy_result"
- "'uid' in copy_result"
- name: verify that the file was marked as changed
assert:
that:
- "copy_result.changed == true"
- name: verify that the file md5sum is correct
assert:
that:
- "copy_result.md5sum == 'c47397529fe81ab62ba3f85e9f4c71f2'"
- name: check the stat results of the file
stat: path={{output_file}}
register: stat_results
- debug: var=stat_results
- name: assert the stat results are correct
assert:
that:
- "stat_results.stat.exists == true"
- "stat_results.stat.isblk == false"
- "stat_results.stat.isfifo == false"
- "stat_results.stat.isreg == true"
- "stat_results.stat.issock == false"
- "stat_results.stat.md5 == 'c47397529fe81ab62ba3f85e9f4c71f2'"
- name: overwrite the file via same means
copy: src=foo.txt dest={{output_file}}
register: copy_result2
- name: assert that the file was not changed
assert:
that:
- "not copy_result2|changed"
- name: overwrite the file using the content system
copy: content="modified" dest={{output_file}}
register: copy_result3
- name: assert that the file has changed
assert:
that:
- "copy_result3|changed"
# test recursive copy
- name: set the output subdirectory
set_fact: output_subdir={{output_dir}}/sub
- name: make an output subdirectory
file: name={{output_subdir}} state=directory
- name: test recursive copy to directory
copy: src=subdir dest={{output_subdir}}
register: recursive_copy_result
- debug: var=recursive_copy_result
- name: check that a file in a directory was transferred
stat: path={{output_dir}}/sub/subdir/bar.txt
register: stat_bar
- name: check that a file in a deeper directory was transferred
stat: path={{output_dir}}/sub/subdir/subdir2/baz.txt
register: stat_bar2
- name: assert recursive copy things
assert:
that:
- "stat_bar.stat.exists"
- "stat_bar2.stat.exists"
# errors on this aren't presently ignored so this test is commented out. But it would be nice to fix.
#
- name: overwrite the file again using the content system, also passing along file params
copy: content="modified" dest={{output_file}}
register: copy_result4
#- name: assert invalid copy input location fails
# copy: src=invalid_file_location_does_not_exist dest={{output_dir}}/file.txt
# ignore_errors: True
# register: failed_copy

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,39 @@
# Test code for facts.d and setup filters
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- set_fact: fact_dir={{output_dir}}/facts.d
- file: path={{ fact_dir }} state=directory
- shell: echo "[general]" > {{ fact_dir }}/preferences.fact
- shell: echo "bar=loaded" >> {{ fact_dir }}/preferences.fact
- setup:
fact_path: "{{ fact_dir | expanduser }}"
filter: "*local*"
register: setup_result
- debug: var=setup_result
- assert:
that:
- "'ansible_facts' in setup_result"
- "'ansible_local' in setup_result.ansible_facts"
- "'preferences' in setup_result.ansible_facts['ansible_local']"
- "'general' in setup_result.ansible_facts['ansible_local']['preferences']"
- "'bar' in setup_result.ansible_facts['ansible_local']['preferences']['general']"
- "setup_result.ansible_facts['ansible_local']['preferences']['general']['bar'] == 'loaded'"

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,42 @@
# test code for the pip module
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: set the output location
set_fact: output_file={{ output_dir }}/motd
- name: fetch the motd
fetch: src=/etc/motd dest={{ output_file }}
register: fetched
- debug: var=fetched
# TODO: check the sudo and non-sudo forms of fetch because in one form we'll do
# the get method of the connection plugin and in the sudo case we'll use the
# fetch module.
- name: diff what we fetched with the original file
shell: diff /etc/motd {{ output_dir }}/motd/127.0.0.1/etc/motd
register: diff
- name: check the diff to make sure they are the same
assert:
that:
'diff.stdout == ""'

View file

@ -0,0 +1 @@
foo.txt

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,168 @@
# Test code for the file module.
# (c) 2014, Richard Isaacson <richard.c.isaacson@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- set_fact: output_file={{output_dir}}/foo.txt
- name: prep with a basic copy
copy: src=foo.txt dest={{output_file}}
- name: verify that we are checking a file and it is present
file: path={{output_file}} state=file
register: file_result
- name: verify that the file was marked as changed
assert:
that:
- "file_result.changed == false"
- "file_result.state == 'file'"
- name: verify that we are checking an absent file
file: path={{output_dir}}/bar.txt state=absent
register: file2_result
- name: verify that the file was marked as changed
assert:
that:
- "file2_result.changed == false"
- "file2_result.state == 'absent'"
- name: verify we can touch a file
file: path={{output_dir}}/baz.txt state=touch
register: file3_result
- name: verify that the file was marked as changed
assert:
that:
- "file3_result.changed == true"
- "file3_result.state == 'file'"
- "file3_result.mode == '0644'"
- name: change file mode
file: path={{output_dir}}/baz.txt mode=0600
register: file4_result
- name: verify that the file was marked as changed
assert:
that:
- "file4_result.changed == true"
- "file4_result.mode == '0600'"
- name: change ownership and group
file: path={{output_dir}}/baz.txt owner=1234 group=1234
- name: create soft link to file
file: src={{output_file}} dest={{output_dir}}/soft.txt state=link
register: file5_result
- name: verify that the file was marked as changed
assert:
that:
- "file5_result.changed == true"
- name: create hard link to file
file: src={{output_file}} dest={{output_dir}}/hard.txt state=hard
register: file6_result
- name: verify that the file was marked as changed
assert:
that:
- "file6_result.changed == true"
- name: create a directory
file: path={{output_dir}}/foobar state=directory
register: file7_result
- name: verify that the file was marked as changed
assert:
that:
- "file7_result.changed == true"
- "file7_result.state == 'directory'"
- name: determine if selinux is installed
shell: which getenforce || exit 0
register: selinux_installed
- name: determine if selinux is enabled
shell: getenforce
register: selinux_enabled
when: selinux_installed.stdout != ""
ignore_errors: true
- name: decide to include or not include selinux tests
include: selinux_tests.yml
when: selinux_installed.stdout != "" and selinux_enabled.stdout != "Disabled"
- name: remote directory foobar
file: path={{output_dir}}/foobar state=absent
- name: remove file foo.txt
file: path={{output_dir}}/foo.txt state=absent
- name: remove file bar.txt
file: path={{output_dir}}/foo.txt state=absent
- name: remove file baz.txt
file: path={{output_dir}}/foo.txt state=absent
- name: copy directory structure over
copy: src=foobar dest={{output_dir}}
- name: Change ownership of a directory with recurse=no(default)
file: path={{output_dir}}/foobar owner=1234
- name: verify that the permission of the directory was set
file: path={{output_dir}}/foobar state=directory
register: file8_result
- name: assert that the directory has changed to have owner 1234
assert:
that:
- "file8_result.uid == 1234"
- name: verify that the permission of a file under the directory was not set
file: path={{output_dir}}/foobar/fileA state=file
register: file9_result
- name: assert the file owner has not changed to 1234
assert:
that:
- "file9_result.uid != 1234"
- name: change the ownership of a directory with recurse=yes
file: path={{output_dir}}/foobar owner=1235 recurse=yes
- name: verify that the permission of the directory was set
file: path={{output_dir}}/foobar state=directory
register: file10_result
- name: assert that the directory has changed to have owner 1235
assert:
that:
- "file10_result.uid == 1235"
- name: verify that the permission of a file under the directory was not set
file: path={{output_dir}}/foobar/fileA state=file
register: file11_result
- name: assert that the file has changed to have owner 1235
assert:
that:
- "file11_result.uid == 1235"
- name: remote directory foobar
file: path={{output_dir}}/foobar state=absent

View file

@ -0,0 +1,30 @@
# Test code for the file module - selinux subtasks.
# (c) 2014, Richard Isaacson <richard.c.isaacson@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: touch a file for testing
file: path={{output_dir}}/foo-se.txt state=touch
register: file_se_result
- name: verify that the file was marked as changed
assert:
that:
- "file_se_result.changed == true"
- "file_se_result.secontext == 'unconfined_u:object_r:admin_home_t:s0'"
- name: remove the file used for testing
file: path={{output_dir}}/foo-se.txt state=absent

View file

@ -0,0 +1,72 @@
This is a test of various filter plugins found in Ansible (ex: core.py), and
not so much a test of the core filters in Jinja2.
Dumping a nested structure to JSON
[
"this is a list element",
{
"this": "is a hash element in a list",
"warp": 9,
"where": "endor"
}
]
Dumping the same structure to YAML
- this is a list element
- this: is a hash element in a list
warp: 9
where: endor
Dumping the same structure to JSON, but don't pretty print
["this is a list element", {"this": "is a hash element in a list", "where": "endor", "warp": 9}]
Dumping the same structure to YAML, but don't pretty print
- this is a list element
- {this: is a hash element in a list, warp: 9, where: endor}
From a recorded task, the changed, failed, success, and skipped
filters are shortcuts to ask if those tasks produced changes, failed,
succeeded, or skipped (as one might guess).
Changed = True
Failed = False
Success = True
Skipped = False
The mandatory filter fails if a variable is not defined and returns the value.
To avoid breaking this test, this variable is already defined.
a = 1
There are various casts available
int = 1
bool = True
String quoting
quoted = quoted
The fileglob module returns the list of things matching a pattern.
fileglob = []
There are also various string operations that work on paths. These do not require
files to exist and are passthrus to the python os.path functions
/etc/motd with basename = motd
/etc/motd with dirname = /etc
TODO: realpath follows symlinks. There isn't a test for this just now.
TODO: add tests for set theory operations like union
TODO: add tests for regex, match, and search

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,40 @@
# test code
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: a dummy task to test the changed and success filters
shell: echo hi
register: some_registered_var
- debug: var=some_registered_var
- name: fill in a basic template
template: src=foo.j2 dest={{output_dir}}/foo.templated mode=0644
register: template_result
- name: copy known good into place
copy: src=foo.txt dest={{output_dir}}/foo.txt
- name: compare templated file to known good
shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt
register: diff_result
- name: verify templated file matches known good
assert:
that:
- 'diff_result.stdout == ""'

View file

@ -0,0 +1,59 @@
This is a test of various filter plugins found in Ansible (ex: core.py), and
not so much a test of the core filters in Jinja2.
Dumping a nested structure to JSON
{{ some_structure | to_nice_json }}
Dumping the same structure to YAML
{{ some_structure | to_nice_yaml }}
Dumping the same structure to JSON, but don't pretty print
{{ some_structure | to_json }}
Dumping the same structure to YAML, but don't pretty print
{{ some_structure | to_yaml }}
From a recorded task, the changed, failed, success, and skipped
filters are shortcuts to ask if those tasks produced changes, failed,
succeeded, or skipped (as one might guess).
Changed = {{ some_registered_var | changed }}
Failed = {{ some_registered_var | failed }}
Success = {{ some_registered_var | success }}
Skipped = {{ some_registered_var | skipped }}
The mandatory filter fails if a variable is not defined and returns the value.
To avoid breaking this test, this variable is already defined.
a = {{ a | mandatory }}
There are various casts available
int = {{ a | int }}
bool = {{ 1 | bool }}
String quoting
quoted = {{ 'quoted' | quote }}
The fileglob module returns the list of things matching a pattern.
fileglob = {{ (output_dir + '/*') | fileglob }}
There are also various string operations that work on paths. These do not require
files to exist and are passthrus to the python os.path functions
/etc/motd with basename = {{ '/etc/motd' | basename }}
/etc/motd with dirname = {{ '/etc/motd' | dirname }}
TODO: realpath follows symlinks. There isn't a test for this just now.
TODO: add tests for set theory operations like union
TODO: add tests for regex, match, and search

View file

@ -0,0 +1,6 @@
some_structure:
- "this is a list element"
-
this: "is a hash element in a list"
warp: 9
where: endor

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,40 @@
# test code for the gem module
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: remove a gem
gem: name=gist state=absent
- name: verify gist is not installed
shell: gem list | egrep '^gist '
register: uninstall
failed_when: "uninstall.rc != 1"
- name: install a gem
gem: name=gist state=present
register: gem_result
- name: verify module output properties
assert:
that:
- "'name' in gem_result"
- "'changed' in gem_result"
- "'state' in gem_result"
- name: verify gist is installed
shell: gem list | egrep '^gist '

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,79 @@
# test code for the git module
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: set where to extract the repo
set_fact: checkout_dir={{ output_dir }}/git
- name: set what repo to use
set_fact: repo=https://github.com/jimi-c/test_role
- name: clean out the output_dir
shell: rm -rf {{ output_dir }}/*
- name: verify that git is installed so this test can continue
shell: which git
- name: initial checkout
git: repo={{ repo }} dest={{ checkout_dir }}
register: git_result
- debug: var=git_result
- shell: ls ~/ansible_testing/git
- name: verify information about the initial clone
assert:
that:
- "'before' in git_result"
- "'after' in git_result"
- "not git_result.before"
- "git_result.changed"
- name: repeated checkout
git: repo={{ repo }} dest={{ checkout_dir }}
register: git_result2
- debug: var=git_result2
- name: check for tags
stat: path={{ checkout_dir }}/.git/refs/tags
register: tags
- name: check for HEAD
stat: path={{ checkout_dir }}/.git/HEAD
register: head
- name: check for remotes
stat: path={{ checkout_dir }}/.git/branches
register: branches
- name: assert presense of tags/trunk/branches
assert:
that:
- "tags.stat.isdir"
- "head.stat.isreg"
- "branches.stat.isdir"
- name: verify on a reclone things are marked unchanged
assert:
that:
- "not git_result2.changed"

View file

@ -0,0 +1,21 @@
# test code for the hash variable behavior
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
---
test_hash:
default_vars: "this is in role default/main.yml"

View file

@ -0,0 +1,18 @@
# test code for the hash variable behavior
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,38 @@
# test code for the hash variable behavior
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: get the hash behavior env setting
shell: env | grep ANSIBLE_HASH_BEHAVIOUR | cut -f2- -d'='
register: hash_behavior
- name: debug hash behavior result
debug: var=hash_behavior.stdout
- name: assert hash behavior is merge or replace
assert:
that:
- "hash_behavior.stdout in ('merge', 'replace')"
- name: debug test_hash var
debug: var=test_hash
- name: assert the dictionary values match
assert:
that:
- "hash_behavior.stdout == 'merge' and test_hash == merged_hash or hash_behavior.stdout == 'replace' and test_hash == replaced_hash"

View file

@ -0,0 +1,21 @@
# test code for the hash variable behavior
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
---
test_hash:
role_vars: "this is in role vars/main.yml"

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,79 @@
# test code for the hg module
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: set where to extract the repo
set_fact: checkout_dir={{ output_dir }}/epdb
- name: set what repo to use
set_fact: repo=https://bitbucket.org/rpathsync/epdb
- name: clean out the output_dir
shell: rm -rf {{ output_dir }}/*
- name: verify that mercurial is installed so this test can continue
shell: which hg
- name: initial checkout
hg: repo={{ repo }} dest={{ checkout_dir }}
register: hg_result
- debug: var=hg_result
#- shell: ls ~/ansible_testing/epdb
- shell: ls {{ checkout_dir }}
- name: verify information about the initial clone
assert:
that:
- "'before' in hg_result"
- "'after' in hg_result"
- "not hg_result.before"
- "hg_result.changed"
- name: repeated checkout
hg: repo={{ repo }} dest={{ checkout_dir }}
register: hg_result2
- debug: var=hg_result2
- name: check for tags
stat: path={{ checkout_dir }}/.hgtags
register: tags
- name: check for remotes
stat: path={{ checkout_dir }}/.hg/branch
register: branches
- debug: var=tags
- debug: var=branches
- name: assert presense of tags/trunk/branches
assert:
that:
- "tags.stat.isreg"
- "head.stat.isreg"
- "branches.stat.isreg"
- name: verify on a reclone things are marked unchanged
assert:
that:
- "not hg_result2.changed"

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,23 @@
# test code
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: this will not stop the playbook
shell: /bin/false
register: failed
ignore_errors: True

View file

@ -0,0 +1,5 @@
This is line 1
This is line 2
REF this is a line for backrefs REF
This is line 4
This is line 5

View file

@ -0,0 +1,20 @@
# test code for the lineinfile module
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
dependencies:
- prepare_tests

View file

@ -0,0 +1,211 @@
# test code for the lineinfile module
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: deploy the test file for lineinfile
copy: src=test.txt dest={{output_dir}}/test.txt
register: result
- name: assert that the test file was deployed
assert:
that:
- "result.changed == true"
- "result.md5sum == '6be7fb7fa7fb758c80a6dc0722979c40'"
- "result.state == 'file'"
- name: insert a line at the beginning of the file, and back it up
lineinfile: dest={{output_dir}}/test.txt state=present line="New line at the beginning" insertbefore="BOF" backup=yes
register: result
- name: assert that the line was inserted at the head of the file
assert:
that:
- "result.changed == true"
- "result.msg == 'line added'"
- "result.backup != ''"
- name: stat the backup file
stat: path={{result.backup}}
register: result
- name: assert the backup file matches the previous md5
assert:
that:
- "result.stat.md5 == '6be7fb7fa7fb758c80a6dc0722979c40'"
- name: stat the test after the insert at the head
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches after the insert at the head
assert:
that:
- "result.stat.md5 == '07c16434644a2a3cc1807c685917443a'"
- name: insert a line at the end of the file
lineinfile: dest={{output_dir}}/test.txt state=present line="New line at the end" insertafter="EOF"
register: result
- name: assert that the line was inserted at the end of the file
assert:
that:
- "result.changed == true"
- "result.msg == 'line added'"
- name: stat the test after the insert at the end
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches after the insert at the end
assert:
that:
- "result.stat.md5 == 'da4c2150e5782fcede1840280ab87eff'"
- name: insert a line after the first line
lineinfile: dest={{output_dir}}/test.txt state=present line="New line after line 1" insertafter="^This is line 1$"
register: result
- name: assert that the line was inserted after the first line
assert:
that:
- "result.changed == true"
- "result.msg == 'line added'"
- name: stat the test after insert after the first line
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches after the insert after the first line
assert:
that:
- "result.stat.md5 == '196722c8faaa28b960bee66fa4cce58c'"
- name: insert a line before the last line
lineinfile: dest={{output_dir}}/test.txt state=present line="New line after line 5" insertbefore="^This is line 5$"
register: result
- name: assert that the line was inserted before the last line
assert:
that:
- "result.changed == true"
- "result.msg == 'line added'"
- name: stat the test after the insert before the last line
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches after the insert before the last line
assert:
that:
- "result.stat.md5 == 'd5955ee042139dfef16dbe3a7334475f'"
- name: replace a line with backrefs
lineinfile: dest={{output_dir}}/test.txt state=present line="This is line 3" backrefs=yes regexp="^(REF) .* \1$"
register: result
- name: assert that the line with backrefs was changed
assert:
that:
- "result.changed == true"
- "result.msg == 'line replaced'"
- name: stat the test after the backref line was replaced
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches after backref line was replaced
assert:
that:
- "result.stat.md5 == '0f585270054e17be242743dd31c6f593'"
- name: remove the middle line
lineinfile: dest={{output_dir}}/test.txt state=absent regexp="^This is line 3$"
register: result
- name: assert that the line was inserted at the head of the file
assert:
that:
- "result.changed == true"
- "result.msg == '1 line(s) removed'"
- name: stat the test after the middle line was removed
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches after the middle line was removed
assert:
that:
- "result.stat.md5 == '661603660051991b79429c2dc68d9a67'"
- name: run a validation script that succeeds
lineinfile: dest={{output_dir}}/test.txt state=absent regexp="^This is line 5$" validate="/bin/true %s"
register: result
- name: assert that the file validated after removing a line
assert:
that:
- "result.changed == true"
- "result.msg == '1 line(s) removed'"
- name: stat the test after the validation succeeded
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches after the validation succeeded
assert:
that:
- "result.stat.md5 == '9af984939bd859f7794661e501b4f1a4'"
- name: run a validation script that fails
lineinfile: dest={{output_dir}}/test.txt state=absent regexp="^This is line 1$" validate="/bin/false %s"
register: result
ignore_errors: yes
- name: assert that the validate failed
assert:
that:
- "result.failed == true"
- name: stat the test after the validation failed
stat: path={{output_dir}}/test.txt
register: result
- name: assert test md5 matches the previous after the validation failed
assert:
that:
- "result.stat.md5 == '9af984939bd859f7794661e501b4f1a4'"
- name: use create=yes
lineinfile: dest={{output_dir}}/new_test.txt create=yes insertbefore=BOF state=present line="This is a new file"
register: result
- name: assert that the new file was created
assert:
that:
- "result.changed == true"
- "result.msg == 'line added'"
- name: validate that the newly created file exists
stat: path={{output_dir}}/new_test.txt
register: result
ignore_errors: yes
- name: assert the newly created test md5 matches
assert:
that:
- "result.stat.md5 == 'fef1d487711facfd7aa2c87d788c19d9'"

View file

@ -0,0 +1,37 @@
# test code for the ping module
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: ping the test
ping:
register: result
- name: assert the ping worked
assert:
that:
- "result.changed == false"
- "result.ping == 'pong'"
- name: ping with data
ping: data="testing"
register: result
- name: assert the ping worked with data
assert:
that:
- "result.changed == false"
- "result.ping == 'testing'"

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,83 @@
# test code for the pip module
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# FIXME: replace the python test package
# first some tests installed system-wide
# verify things were not installed to start with
- name: ensure a package is not installed (precondition setup)
pip: name={{ pip_test_package }} state=absent
# verify that a package that is uninstalled being set to absent
# results in an unchanged state and that the test package is not
# installed
- name: ensure a package is not installed
pip: name={{ pip_test_package }} state=absent
register: uninstall_result
- name: removing an unremoved package should return unchanged
assert:
that:
- "not uninstall_result.changed"
- shell: "python -c 'import {{ pip_test_package }}'"
register: absent_result
ignore_errors: True
- name: verify {{ pip_test_package }} is not present
assert:
that:
- "absent_result.rc != 0"
# now we're going to install the test package knowing it is uninstalled
# and check that installation was ok
- name: ensure a package is installed
pip: name={{ pip_test_package }} state=present
register: install_result
- name: verify we recorded a change
assert:
that:
- "install_result.changed == True"
- shell: "python -c 'import {{ pip_test_package }}'"
register: installed_result
# now remove it to test uninstallation of a package we are sure is installed
- name: now uninstall so we can see that a change occured
pip: name={{ pip_test_package }} state=absent
register: absent2
- name: assert a change occured on uninstallation
assert:
that:
- "absent2.changed"
# put the test package back
- name: now put it back in case someone wanted it (like us!)
pip: name={{ pip_test_package }} state=present

View file

@ -0,0 +1,7 @@
[Unit]
Description=Ansible Test Service
[Service]
ExecStart=/usr/sbin/ansible_test_service
ExecReload=/bin/true
Type=forking

View file

@ -0,0 +1,134 @@
#!/bin/sh
#
# LSB header
### BEGIN INIT INFO
# Provides: ansible-test
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: test daemon for ansible
# Description: This is a test daemon used by ansible for testing only
### END INIT INFO
# chkconfig header
# chkconfig: 345 99 99
# description: This is a test daemon used by ansible for testing only
#
# processname: /usr/sbin/ansible_test_service
# Sanity checks.
[ -x /usr/sbin/ansible_test_service ] || exit 0
DEBIAN_VERSION=/etc/debian_version
SUSE_RELEASE=/etc/SuSE-release
# Source function library.
if [ -f $DEBIAN_VERSION ]; then
. /lib/lsb/init-functions
elif [ -f $SUSE_RELEASE -a -r /etc/rc.status ]; then
. /etc/rc.status
else
. /etc/rc.d/init.d/functions
fi
SERVICE=ansible_test_service
PROCESS=ansible_test_service
CONFIG_ARGS=" "
if [ -f $DEBIAN_VERSION ]; then
LOCKFILE=/var/lock/$SERVICE
else
LOCKFILE=/var/lock/subsys/$SERVICE
fi
RETVAL=0
start() {
echo -n "Starting ansible test daemon: "
if [ -f $SUSE_RELEASE ]; then
startproc -p /var/run/${SERVICE}.pid -f /usr/sbin/ansible_test_service
rc_status -v
elif [ -e $DEBIAN_VERSION ]; then
if [ -f $LOCKFILE ]; then
echo -n "already started, lock file found"
RETVAL=1
elif /bin/python /usr/sbin/ansible_test_service; then
echo -n "OK"
RETVAL=0
fi
else
daemon --check $SERVICE $PROCESS --daemonize $CONFIG_ARGS
fi
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
echo -n "Stopping ansible test daemon: "
if [ -f $SUSE_RELEASE ]; then
killproc -TERM /usr/sbin/ansible_test_service
rc_status -v
elif [ -f $DEBIAN_VERSION ]; then
# Added this since Debian's start-stop-daemon doesn't support spawned processes
if ps -ef | grep "/bin/python /usr/sbin/ansible_test_service" | grep -v grep | awk '{print $2}' | xargs kill &> /dev/null; then
echo -n "OK"
RETVAL=0
else
echo -n "Daemon is not started"
RETVAL=1
fi
else
killproc -p /var/run/${SERVICE}.pid
fi
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
rm -f $LOCKFILE
rm -f /var/run/$SERVICE.pid
fi
}
restart() {
stop
start
}
# See how we were called.
case "$1" in
start|stop|restart)
$1
;;
status)
if [ -f $SUSE_RELEASE ]; then
echo -n "Checking for ansible test service "
checkproc /usr/sbin/ansible_test_service
rc_status -v
elif [ -f $DEBIAN_VERSION ]; then
if [ -f $LOCKFILE ]; then
RETVAL=0
echo "ansible test is running."
else
RETVAL=1
echo "ansible test is stopped."
fi
else
status $PROCESS
RETVAL=$?
fi
;;
condrestart)
[ -f $LOCKFILE ] && restart || :
;;
reload)
echo "ok"
RETVAL=0
;;
*)
echo "Usage: $0 {start|stop|status|restart|condrestart|reload}"
exit 1
;;
esac
exit $RETVAL

View file

@ -0,0 +1,9 @@
description "ansible test daemon"
start on runlevel [345]
stop on runlevel [!345]
expect daemon
exec ansible_test_service

View file

@ -0,0 +1,67 @@
#!/usr/bin/env python
# this is mostly based off of the code found here:
# http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/
import os
import resource
import sys
import time
UMASK = 0
WORKDIR = "/"
MAXFD = 1024
if (hasattr(os, "devnull")):
REDIRECT_TO = os.devnull
else:
REDIRECT_TO = "/dev/null"
def createDaemon():
try:
pid = os.fork()
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if (pid == 0):
os.setsid()
try:
pid = os.fork()
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if (pid == 0):
os.chdir(WORKDIR)
os.umask(UMASK)
else:
f = open('/var/run/ansible_test_service.pid', 'w')
f.write("%d\n" % pid)
f.close()
os._exit(0)
else:
os._exit(0)
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
if (maxfd == resource.RLIM_INFINITY):
maxfd = MAXFD
for fd in range(0, maxfd):
try:
os.close(fd)
except OSError: # ERROR, fd wasn't open to begin with (ignored)
pass
os.open(REDIRECT_TO, os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
return(0)
if __name__ == "__main__":
retCode = createDaemon()
while True:
time.sleep(1000)

View file

@ -0,0 +1,20 @@
# test code for the service module
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
dependencies:
- prepare_tests

View file

@ -0,0 +1,108 @@
- name: install the test daemon script
copy: src=ansible_test_service dest=/usr/sbin/ansible_test_service mode=755
register: install_result
- name: assert that the daemon script was installed
assert:
that:
- "install_result.dest == '/usr/sbin/ansible_test_service'"
- "install_result.md5sum == '9ad49eaf390b30b1206b793ec71200ed'"
- "install_result.state == 'file'"
- "install_result.mode == '0755'"
- include: 'sysv_setup.yml'
when: ansible_distribution in ('RHEL', 'CentOS', 'ScientificLinux')
- include: 'systemd_setup.yml'
when: ansible_distribution == 'Fedora'
- include: 'upstart_setup.yml'
when: ansible_distribution == 'Ubuntu'
- name: enable the ansible test service
service: name=ansible_test enabled=yes
register: enable_result
- name: assert that the service was enabled
assert:
that:
- "enable_result.enabled == true"
- name: start the ansible test service
service: name=ansible_test state=started
register: start_result
- name: assert that the service was started
assert:
that:
- "start_result.state == 'started'"
- name: find the service with a pattern
service: name=ansible_test pattern="ansible_test_ser*" state=started
register: start2_result
- name: assert that the service was started via the pattern
assert:
that:
- "start2_result.name == 'ansible_test'"
- "start2_result.state == 'started'"
- name: restart the ansible test service
service: name=ansible_test state=restarted
register: restart_result
- name: assert that the service was restarted
assert:
that:
- "restart_result.state == 'started'"
- name: restart the ansible test service with a sleep
service: name=ansible_test state=restarted sleep=2
register: restart_sleep_result
- name: assert that the service was restarted with a sleep
assert:
that:
- "restart_sleep_result.state == 'started'"
- name: reload the ansible test service
service: name=ansible_test state=reloaded
register: reload_result
- name: assert that the service was reloaded
assert:
that:
- "reload_result.state == 'started'"
- name: stop the ansible test service
service: name=ansible_test state=stopped
register: stop_result
- name: assert that the service was stopped
assert:
that:
- "stop_result.state == 'stopped'"
- name: disable the ansible test service
service: name=ansible_test enabled=no
register: disable_result
- name: assert that the service was disabled
assert:
that:
- "disable_result.enabled == false"
- name: remove the test daemon script
file: path=/usr/sbin/ansible_test_service state=absent
register: remove_result
- name: assert that the test daemon script was removed
assert:
that:
- "remove_result.path == '/usr/sbin/ansible_test_service'"
- "remove_result.state == 'absent'"
- include: 'sysv_cleanup.yml'
when: ansible_distribution in ('RHEL', 'CentOS', 'ScientificLinux')
- include: 'systemd_cleanup.yml'
when: ansible_distribution == 'Fedora'
- include: 'upstart_cleanup.yml'
when: ansible_distribution == 'Ubuntu'

View file

@ -0,0 +1,19 @@
- name: remove the systemd unit file
file: path=/usr/lib/systemd/system/ansible_test.service state=absent
register: remove_systemd_result
- name: assert that the systemd unit file was removed
assert:
that:
- "remove_systemd_result.path == '/usr/lib/systemd/system/ansible_test.service'"
- "remove_systemd_result.state == 'absent'"
- name: make sure systemd is reloaded
shell: systemctl daemon-reload
register: restart_systemd_result
- name: assert that systemd was reloaded
assert:
that:
- "restart_systemd_result.rc == 0"

View file

@ -0,0 +1,12 @@
- name: install the systemd unit file
copy: src=ansible.systemd dest=/usr/lib/systemd/system/ansible_test.service
register: install_systemd_result
- name: assert that the systemd unit file was installed
assert:
that:
- "install_systemd_result.dest == '/usr/lib/systemd/system/ansible_test.service'"
- "install_systemd_result.state == 'file'"
- "install_systemd_result.mode == '0644'"
- "install_systemd_result.md5sum == 'f634df77d9160ab05bad4ed49d82a0d0'"

View file

@ -0,0 +1,10 @@
- name: remove the sysV init file
file: path=/etc/init.d/ansible_test state=absent
register: remove_sysv_result
- name: assert that the sysV init file was removed
assert:
that:
- "remove_sysv_result.path == '/etc/init.d/ansible_test'"
- "remove_sysv_result.state == 'absent'"

View file

@ -0,0 +1,12 @@
- name: install the sysV init file
copy: src=ansible.sysv dest=/etc/init.d/ansible_test mode=0755
register: install_sysv_result
- name: assert that the sysV init file was installed
assert:
that:
- "install_sysv_result.dest == '/etc/init.d/ansible_test'"
- "install_sysv_result.state == 'file'"
- "install_sysv_result.mode == '0755'"
- "install_sysv_result.md5sum == 'ebf6a9064ca8628187f3a6caf8e2a279'"

View file

@ -0,0 +1,10 @@
- name: remove the upstart init file
file: path=/etc/init/ansible_test state=absent
register: remove_upstart_result
- name: assert that the upstart init file was removed
assert:
that:
- "remove_upstart_result.path == '/etc/init/ansible_test'"
- "remove_upstart_result.state == 'absent'"

View file

@ -0,0 +1,12 @@
- name: install the upstart init file
copy: src=ansible.upstart dest=/etc/init/ansible_test mode=0755
register: install_upstart_result
- name: assert that the upstart init file was installed
assert:
that:
- "install_upstart_result.dest == '/etc/init/ansible_test'"
- "install_upstart_result.state == 'file'"
- "install_upstart_result.mode == '0755'"
- "install_upstart_result.md5sum == 'ab3900ea4de8423add764c12aeb90c01'"

View file

@ -0,0 +1 @@
templated_var_loaded

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,64 @@
# test code for the stat module
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: make a new file
copy: dest={{output_dir}}/foo.txt mode=0644 content="hello world"
- name: check stat of file
stat: path={{output_dir}}/foo.txt
register: stat_result
- debug: var=stat_result
- assert:
that:
- "'changed' in stat_result"
- "stat_result.changed == false"
- "'stat' in stat_result"
- "'atime' in stat_result.stat"
- "'ctime' in stat_result.stat"
- "'dev' in stat_result.stat"
- "'exists' in stat_result.stat"
- "'gid' in stat_result.stat"
- "'inode' in stat_result.stat"
- "'isblk' in stat_result.stat"
- "'ischr' in stat_result.stat"
- "'isdir' in stat_result.stat"
- "'isfifo' in stat_result.stat"
- "'isgid' in stat_result.stat"
- "'isreg' in stat_result.stat"
- "'issock' in stat_result.stat"
- "'isuid' in stat_result.stat"
- "'md5' in stat_result.stat"
- "stat_result.stat.md5 == '5eb63bbbe01eeed093cb22bb8f5acdc3'"
- "'mode' in stat_result.stat" # why is this 420?
- "'mtime' in stat_result.stat"
- "'nlink' in stat_result.stat"
- "'pw_name' in stat_result.stat"
- "'rgrp' in stat_result.stat"
- "'roth' in stat_result.stat"
- "'rusr' in stat_result.stat"
- "'size' in stat_result.stat"
- "'uid' in stat_result.stat"
- "'wgrp' in stat_result.stat"
- "'woth' in stat_result.stat"
- "'wusr' in stat_result.stat"
- "'xgrp' in stat_result.stat"
- "'xoth' in stat_result.stat"
- "'xusr' in stat_result.stat"

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,97 @@
# test code for the svn module
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: set where to extract the repo
set_fact: checkout_dir={{ output_dir }}/svn
- name: set what repo to use
set_fact: repo=https://github.com/jimi-c/test_role
- name: clean out the output_dir
shell: rm -rf {{ output_dir }}/*
- name: verify that subversion is installed so this test can continue
shell: which svn
# checks out every branch so using a small repo
- name: initial checkout
subversion: repo={{ repo }} dest={{ checkout_dir }}
register: subverted
- debug: var=subverted
- shell: ls ~/ansible_testing/svn
# FIXME: the before/after logic here should be fixed to make them hashes, see GitHub 6078
# looks like this: {
# "after": [
# "Revision: 9",
# "URL: https://github.com/jimi-c/test_role"
# ],
# "befbore": null,
# "changed": true,
# "invocation": {
# "module_args": "repo=https://github.com/jimi-c/test_role dest=~/ansible_testing/svn",
# "module_name": "subversion"
# },
# "item": ""
# }
- name: verify information about the initial clone
assert:
that:
- "'after' in subverted"
- "subverted.after.1 == 'URL: https://github.com/jimi-c/test_role'"
- "not subverted.before"
- "subverted.changed"
- name: repeated checkout
subversion: repo={{ repo }} dest={{ checkout_dir }}
register: subverted2
- name: check for tags
stat: path={{ checkout_dir }}/tags
register: tags
- name: check for trunk
stat: path={{ checkout_dir }}/trunk
register: trunk
- name: check for branches
stat: path={{ checkout_dir }}/branches
register: branches
- name: assert presense of tags/trunk/branches
assert:
that:
- "tags.stat.isdir"
- "trunk.stat.isdir"
- "branches.stat.isdir"
# FIXME: this needs to be fixed in the code see GitHub 6079
#- name: verify on a reclone things are marked unchanged
# assert:
# that:
# - "not subverted.changed"
# TBA: test for additional options or URL variants welcome

View file

@ -0,0 +1 @@
templated_var_loaded

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,40 @@
# test code for the synchronize module
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# FIXME: tags should auto-apply to role dependencies
- name: cleanup old files
shell: rm -rf {{output_dir}}/*
- name: make a new file
copy: dest={{output_dir}}/foo.txt mode=0644 content="hello world"
- name: synchronize file to new filename
synchronize: src={{output_dir}}/foo.txt dest={{output_dir}}/foo.result
register: sync_result
- debug: var=sync_result
- assert:
that:
- "'changed' in sync_result"
- "sync_result.changed == true"
- "'cmd' in sync_result"
- "'rsync' in sync_result.cmd"
- "'msg' in sync_result"
- "sync_result.msg == '>f+++++++++ foo.txt\n'"

View file

@ -0,0 +1 @@
templated_var_loaded

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,66 @@
# test code for the template module
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: fill in a basic template
template: src=foo.j2 dest={{output_dir}}/foo.templated mode=0644
register: template_result
- assert:
that:
- "'changed' in template_result"
- "'dest' in template_result"
- "'group' in template_result"
- "'gid' in template_result"
- "'md5sum' in template_result"
- "'owner' in template_result"
- "'size' in template_result"
- "'src' in template_result"
- "'state' in template_result"
- "'uid' in template_result"
- name: verify that the file was marked as changed
assert:
that:
- "template_result.changed == true"
# VERIFY CONTENTS
- name: copy known good into place
copy: src=foo.txt dest={{output_dir}}/foo.txt
- name: compare templated file to known good
shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt
register: diff_result
- name: verify templated file matches known good
assert:
that:
- 'diff_result.stdout == ""'
- "diff_result.rc == 0"
# VERIFY MODE
- name: set file mode
file: path={{output_dir}}/foo.templated mode=0644
register: file_result
- name: ensure file mode did not change
assert:
that:
- "file_result.changed != True"

View file

@ -0,0 +1 @@
{{ templated_var }}

View file

@ -0,0 +1 @@
templated_var: templated_var_loaded

View file

@ -0,0 +1 @@
foo.txt

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,86 @@
# Test code for the unarchive module.
# (c) 2014, Richard Isaacson <richard.c.isaacson@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: prep our file
copy: src=foo.txt dest={{output_dir}}/foo-unarchive.txt
- name: prep a tar file
shell: tar cvf test-unarchive.tar foo-unarchive.txt chdir={{output_dir}}
- name: prep a tar.gz file
shell: tar cvf test-unarchive.tar.gz foo-unarchive.txt chdir={{output_dir}}
- name: prep a zip file
shell: tar cvf test-unarchive.zip foo-unarchive.txt chdir={{output_dir}}
- name: create our tar unarchive destination
file: path={{output_dir}}/test-unarchive-tar state=directory
- name: unarchive a tar file
unarchive: src={{output_dir}}/test-unarchive.tar dest="{{output_dir | expanduser}}/test-unarchive-tar" copy=no
register: unarchive01
- name: verify that the file was marked as changed
assert:
that:
- "unarchive01.changed == true"
- name: verify that the file was unarchived
file: path={{output_dir}}/test-unarchive-tar/foo-unarchive.txt state=file
- name: remove our tar unarchive destination
file: path={{output_dir}}/test-unarchive-tar state=absent
- name: create our tar.gz unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive a tar.gz file
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz copy=no
register: unarchive02
- name: verify that the file was marked as changed
assert:
that:
- "unarchive02.changed == true"
- name: verify that the file was unarchived
file: path={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt state=file
- name: remove our tar.gz unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=absent
- name: create our zip unarchive destination
file: path={{output_dir}}/test-unarchive-zip state=directory
- name: unarchive a zip file
unarchive: src={{output_dir}}/test-unarchive.zip dest={{output_dir | expanduser}}/test-unarchive-zip copy=no
register: unarchive03
- name: verify that the file was marked as changed
assert:
that:
- "unarchive03.changed == true"
- name: verify that the file was unarchived
file: path={{output_dir}}/test-unarchive-zip/foo-unarchive.txt state=file
- name: remove our tar unarchive destination
file: path={{output_dir}}/test-unarchive-zip state=absent
- name: remove our test file for the archive
file: path={{output_dir}}/foo-unarchive.txt state=absent

View file

@ -0,0 +1,4 @@
etest: "from role defaults"
role_var_beats_default: "shouldn't see this"
parameterized_beats_default: "shouldn't see this"
inventory_beats_default: "shouldn't see this"

View file

@ -0,0 +1,77 @@
The value of groups_tree_var = 4000.
This comes from host, not the parents or grandparents.
The value of the grandparent variable grandparent_var is
not overridden and is = 2000
The value of the parent variable is not overriden and
is = 6000
The variable 'overridden_in_parent' is set in the parent
and grandparent, so the parent wins. It's value is = 1000.
The values of 'uno', 'dos', and 'tres' are set in group_vars/all but 'tres' is
set to the value of 'three' in group_vars/local, which should override it.
uno = 1
dos = 2
tres = three
The values of 'a', 'b', 'c', and 'd' are set in host_vars/local and should not
be clobbered by values that are also set in group_vars.
a = 1
b = 2
c = 3
d = 4
The value of 'badwolf' is set via the include_vars plugin.
badwolf = badwolf
The value of 'winter' is set via the main.yml in the role.
winter = coming
Here's an arbitrary variable set as vars_files in the playbook.
vars_file_var = 321
And vars.
vars = 123
Variables about other hosts can be looked up via hostvars. This includes
facts but here we'll just access a variable defined in the groups.
999
Ansible has pretty basic precedence rules for variable overriding. We already have
some tests above about group order. Here are a few more.
* -e variables always win
* then comes "most everything else"
* then comes variables defined in inventory
* then "role defaults", which are the most "defaulty" and lose in priority to everything.
Given the above rules, here's a test that a -e variable overrides inventory,
and also defaults, and role vars.
etest = from -e
Now a test to make sure role variables can override inventory variables.
role_var_beats_inventory = chevron 5 encoded
Role variables should also beat defaults.
role_var_beats_default = chevron 6 encoded
But defaults are lower priority than inventory, so inventory should win.
inventory_beats_default = narf
That's the end of the precedence tests for now, but more are welcome.

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,36 @@
# test code
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- include_vars: more_vars.yml
- name: deploy a template that will use variables at various levels
template: src=foo.j2 dest={{output_dir}}/foo.templated
register: template_result
- name: copy known good into place
copy: src=foo.txt dest={{output_dir}}/foo.txt
- name: compare templated file to known good
shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt
register: diff_result
- name: verify templated file matches known good
assert:
that:
- 'diff_result.stdout == ""'

View file

@ -0,0 +1,77 @@
The value of groups_tree_var = {{ groups_tree_var }}.
This comes from host, not the parents or grandparents.
The value of the grandparent variable grandparent_var is
not overridden and is = {{ grandparent_var }}
The value of the parent variable is not overriden and
is = {{ parent_var }}
The variable 'overridden_in_parent' is set in the parent
and grandparent, so the parent wins. It's value is = {{ overridden_in_parent }}.
The values of 'uno', 'dos', and 'tres' are set in group_vars/all but 'tres' is
set to the value of 'three' in group_vars/local, which should override it.
uno = {{ uno }}
dos = {{ dos }}
tres = {{ tres }}
The values of 'a', 'b', 'c', and 'd' are set in host_vars/local and should not
be clobbered by values that are also set in group_vars.
a = {{ a }}
b = {{ b }}
c = {{ c }}
d = {{ d }}
The value of 'badwolf' is set via the include_vars plugin.
badwolf = {{ badwolf }}
The value of 'winter' is set via the main.yml in the role.
winter = {{ winter }}
Here's an arbitrary variable set as vars_files in the playbook.
vars_file_var = {{ vars_file_var }}
And vars.
vars = {{ vars_var }}
Variables about other hosts can be looked up via hostvars. This includes
facts but here we'll just access a variable defined in the groups.
{{ hostvars['testhost2']['a'] }}
Ansible has pretty basic precedence rules for variable overriding. We already have
some tests above about group order. Here are a few more.
* -e variables always win
* then comes "most everything else"
* then comes variables defined in inventory
* then "role defaults", which are the most "defaulty" and lose in priority to everything.
Given the above rules, here's a test that a -e variable overrides inventory,
and also defaults, and role vars.
etest = {{ etest }}
Now a test to make sure role variables can override inventory variables.
role_var_beats_inventory = {{ role_var_beats_inventory }}
Role variables should also beat defaults.
role_var_beats_default = {{ role_var_beats_default }}
But defaults are lower priority than inventory, so inventory should win.
inventory_beats_default = {{ inventory_beats_default }}
That's the end of the precedence tests for now, but more are welcome.

View file

@ -0,0 +1,4 @@
winter: coming
etest: 'from role vars'
role_var_beats_inventory: 'chevron 5 encoded'
role_var_beats_default: 'chevron 6 encoded'

View file

@ -0,0 +1 @@
badwolf: badwolf

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_tests

Some files were not shown because too many files have changed in this diff Show more