summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/check_mode
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/check_mode')
-rw-r--r--test/integration/targets/check_mode/aliases2
-rw-r--r--test/integration/targets/check_mode/check_mode-not-on-cli.yml37
-rw-r--r--test/integration/targets/check_mode/check_mode-on-cli.yml36
-rw-r--r--test/integration/targets/check_mode/check_mode.yml7
-rw-r--r--test/integration/targets/check_mode/roles/test_always_run/meta/main.yml17
-rw-r--r--test/integration/targets/check_mode/roles/test_always_run/tasks/main.yml29
-rw-r--r--test/integration/targets/check_mode/roles/test_check_mode/files/foo.txt1
-rw-r--r--test/integration/targets/check_mode/roles/test_check_mode/tasks/main.yml50
-rw-r--r--test/integration/targets/check_mode/roles/test_check_mode/templates/foo.j21
-rw-r--r--test/integration/targets/check_mode/roles/test_check_mode/vars/main.yml1
-rwxr-xr-xtest/integration/targets/check_mode/runme.sh7
11 files changed, 188 insertions, 0 deletions
diff --git a/test/integration/targets/check_mode/aliases b/test/integration/targets/check_mode/aliases
new file mode 100644
index 0000000..1d28bdb
--- /dev/null
+++ b/test/integration/targets/check_mode/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group5
+context/controller
diff --git a/test/integration/targets/check_mode/check_mode-not-on-cli.yml b/test/integration/targets/check_mode/check_mode-not-on-cli.yml
new file mode 100644
index 0000000..1b0c734
--- /dev/null
+++ b/test/integration/targets/check_mode/check_mode-not-on-cli.yml
@@ -0,0 +1,37 @@
+---
+# Run withhout --check
+- hosts: testhost
+ gather_facts: False
+ tasks:
+ - command: 'echo ran'
+ register: command_out
+
+ - debug: var=command_out
+ - name: check that this did not run in check mode
+ assert:
+ that:
+ - '"ran" in command_out["stdout"]'
+
+- hosts: testhost
+ gather_facts: False
+ check_mode: True
+ tasks:
+ - command: 'echo ran'
+ register: command_out
+
+ - name: check that play level check_mode overrode the cli
+ assert:
+ that:
+ - '"check mode" in command_out["msg"]'
+
+- hosts: testhost
+ gather_facts: False
+ tasks:
+ - command: 'echo ran'
+ register: command_out
+ check_mode: True
+
+ - name: check that task level check_mode overrode the cli
+ assert:
+ that:
+ - '"check mode" in command_out["msg"]'
diff --git a/test/integration/targets/check_mode/check_mode-on-cli.yml b/test/integration/targets/check_mode/check_mode-on-cli.yml
new file mode 100644
index 0000000..0af34b8
--- /dev/null
+++ b/test/integration/targets/check_mode/check_mode-on-cli.yml
@@ -0,0 +1,36 @@
+---
+# Run with --check
+- hosts: testhost
+ gather_facts: False
+ tasks:
+ - command: 'echo ran'
+ register: command_out
+
+ - name: check that this did not run in check mode
+ assert:
+ that:
+ - '"check mode" in command_out["msg"]'
+
+- hosts: testhost
+ gather_facts: False
+ check_mode: False
+ tasks:
+ - command: 'echo ran'
+ register: command_out
+
+ - name: check that play level check_mode overrode the cli
+ assert:
+ that:
+ - '"ran" in command_out["stdout"]'
+
+- hosts: testhost
+ gather_facts: False
+ tasks:
+ - command: 'echo ran'
+ register: command_out
+ check_mode: False
+
+ - name: check that task level check_mode overrode the cli
+ assert:
+ that:
+ - '"ran" in command_out["stdout"]'
diff --git a/test/integration/targets/check_mode/check_mode.yml b/test/integration/targets/check_mode/check_mode.yml
new file mode 100644
index 0000000..a577750
--- /dev/null
+++ b/test/integration/targets/check_mode/check_mode.yml
@@ -0,0 +1,7 @@
+- name: Test that check works with check_mode specified in roles
+ hosts: testhost
+ vars:
+ - output_dir: .
+ roles:
+ - { role: test_always_run, tags: test_always_run }
+ - { role: test_check_mode, tags: test_check_mode }
diff --git a/test/integration/targets/check_mode/roles/test_always_run/meta/main.yml b/test/integration/targets/check_mode/roles/test_always_run/meta/main.yml
new file mode 100644
index 0000000..d06fd48
--- /dev/null
+++ b/test/integration/targets/check_mode/roles/test_always_run/meta/main.yml
@@ -0,0 +1,17 @@
+# test code for the check_mode: no 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/>.
diff --git a/test/integration/targets/check_mode/roles/test_always_run/tasks/main.yml b/test/integration/targets/check_mode/roles/test_always_run/tasks/main.yml
new file mode 100644
index 0000000..59bfb1d
--- /dev/null
+++ b/test/integration/targets/check_mode/roles/test_always_run/tasks/main.yml
@@ -0,0 +1,29 @@
+# test code for the check_mode: no 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"
+ check_mode: no
+ register: result
+
+- name: assert that the command was run
+ assert:
+ that:
+ - "result.changed == true"
+ - "result.stdout == 'running'"
+ - "result.rc == 0"
diff --git a/test/integration/targets/check_mode/roles/test_check_mode/files/foo.txt b/test/integration/targets/check_mode/roles/test_check_mode/files/foo.txt
new file mode 100644
index 0000000..3e96db9
--- /dev/null
+++ b/test/integration/targets/check_mode/roles/test_check_mode/files/foo.txt
@@ -0,0 +1 @@
+templated_var_loaded
diff --git a/test/integration/targets/check_mode/roles/test_check_mode/tasks/main.yml b/test/integration/targets/check_mode/roles/test_check_mode/tasks/main.yml
new file mode 100644
index 0000000..f926d14
--- /dev/null
+++ b/test/integration/targets/check_mode/roles/test_check_mode/tasks/main.yml
@@ -0,0 +1,50 @@
+# 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 in check mode
+ template: src=foo.j2 dest={{output_dir}}/checkmode_foo.templated mode=0644
+ register: template_result
+
+- name: check whether file exists
+ stat: path={{output_dir}}/checkmode_foo.templated
+ register: foo
+
+- name: verify that the file was marked as changed in check mode
+ assert:
+ that:
+ - "template_result is changed"
+ - "not foo.stat.exists"
+
+- name: Actually create the file, disable check mode
+ template: src=foo.j2 dest={{output_dir}}/checkmode_foo.templated2 mode=0644
+ check_mode: no
+ register: checkmode_disabled
+
+- name: fill in template with new content
+ template: src=foo.j2 dest={{output_dir}}/checkmode_foo.templated2 mode=0644
+ register: template_result2
+
+- name: remove templated file
+ file: path={{output_dir}}/checkmode_foo.templated2 state=absent
+ check_mode: no
+
+- name: verify that the file was not changed
+ assert:
+ that:
+ - "checkmode_disabled is changed"
+ - "template_result2 is not changed"
diff --git a/test/integration/targets/check_mode/roles/test_check_mode/templates/foo.j2 b/test/integration/targets/check_mode/roles/test_check_mode/templates/foo.j2
new file mode 100644
index 0000000..55aab8f
--- /dev/null
+++ b/test/integration/targets/check_mode/roles/test_check_mode/templates/foo.j2
@@ -0,0 +1 @@
+{{ templated_var }}
diff --git a/test/integration/targets/check_mode/roles/test_check_mode/vars/main.yml b/test/integration/targets/check_mode/roles/test_check_mode/vars/main.yml
new file mode 100644
index 0000000..1e8f64c
--- /dev/null
+++ b/test/integration/targets/check_mode/roles/test_check_mode/vars/main.yml
@@ -0,0 +1 @@
+templated_var: templated_var_loaded
diff --git a/test/integration/targets/check_mode/runme.sh b/test/integration/targets/check_mode/runme.sh
new file mode 100755
index 0000000..954ac6f
--- /dev/null
+++ b/test/integration/targets/check_mode/runme.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+set -eux
+
+ansible-playbook check_mode.yml -i ../../inventory -v --check "$@"
+ansible-playbook check_mode-on-cli.yml -i ../../inventory -v --check "$@"
+ansible-playbook check_mode-not-on-cli.yml -i ../../inventory -v "$@"