summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/special_vars
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
commit8a754e0858d922e955e71b253c139e071ecec432 (patch)
tree527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/special_vars
parentInitial commit. (diff)
downloadansible-core-upstream/2.14.3.tar.xz
ansible-core-upstream/2.14.3.zip
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--test/integration/targets/special_vars/aliases3
-rw-r--r--test/integration/targets/special_vars/meta/main.yml2
-rw-r--r--test/integration/targets/special_vars/tasks/main.yml100
-rw-r--r--test/integration/targets/special_vars/templates/foo.j27
-rw-r--r--test/integration/targets/special_vars/vars/main.yml0
-rw-r--r--test/integration/targets/special_vars_hosts/aliases2
-rw-r--r--test/integration/targets/special_vars_hosts/inventory3
-rw-r--r--test/integration/targets/special_vars_hosts/playbook.yml53
-rwxr-xr-xtest/integration/targets/special_vars_hosts/runme.sh7
9 files changed, 177 insertions, 0 deletions
diff --git a/test/integration/targets/special_vars/aliases b/test/integration/targets/special_vars/aliases
new file mode 100644
index 0000000..0010517
--- /dev/null
+++ b/test/integration/targets/special_vars/aliases
@@ -0,0 +1,3 @@
+shippable/posix/group4
+needs/target/include_parent_role_vars
+context/controller
diff --git a/test/integration/targets/special_vars/meta/main.yml b/test/integration/targets/special_vars/meta/main.yml
new file mode 100644
index 0000000..07faa21
--- /dev/null
+++ b/test/integration/targets/special_vars/meta/main.yml
@@ -0,0 +1,2 @@
+dependencies:
+ - prepare_tests
diff --git a/test/integration/targets/special_vars/tasks/main.yml b/test/integration/targets/special_vars/tasks/main.yml
new file mode 100644
index 0000000..0e71f1d
--- /dev/null
+++ b/test/integration/targets/special_vars/tasks/main.yml
@@ -0,0 +1,100 @@
+# test code for the template module
+# (c) 2015, Brian Coca <bcoca@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: verify ansible_managed
+ template: src=foo.j2 dest={{output_dir}}/special_vars.yaml
+
+- name: read the file into facts
+ include_vars: "{{output_dir}}/special_vars.yaml"
+
+
+- name: verify all test vars are defined
+ assert:
+ that:
+ - 'item in hostvars[inventory_hostname].keys()'
+ with_items:
+ - test_template_host
+ - test_template_path
+ - test_template_mtime
+ - test_template_uid
+ - test_template_fullpath
+ - test_template_run_date
+ - test_ansible_managed
+
+- name: ensure that role_name exists in role_names, ansible_play_role_names, ansible_role_names, and not in ansible_dependent_role_names
+ assert:
+ that:
+ - "role_name in role_names"
+ - "role_name in ansible_play_role_names"
+ - "role_name in ansible_role_names"
+ - "role_name not in ansible_dependent_role_names"
+
+- name: ensure that our dependency (prepare_tests) exists in ansible_role_names and ansible_dependent_role_names, but not in role_names or ansible_play_role_names
+ assert:
+ that:
+ - "'prepare_tests' in ansible_role_names"
+ - "'prepare_tests' in ansible_dependent_role_names"
+ - "'prepare_tests' not in role_names"
+ - "'prepare_tests' not in ansible_play_role_names"
+
+- name: ensure that ansible_role_names is the sum of ansible_play_role_names and ansible_dependent_role_names
+ assert:
+ that:
+ - "(ansible_play_role_names + ansible_dependent_role_names)|unique|sort|list == ansible_role_names|sort|list"
+
+- name: check that ansible_parent_role_names is normally unset when not included/imported (before including other roles)
+ assert:
+ that:
+ - "ansible_parent_role_names is undefined"
+ - "ansible_parent_role_paths is undefined"
+
+- name: ansible_parent_role_names - test functionality by including another role
+ include_role:
+ name: include_parent_role_vars
+ tasks_from: included_by_other_role.yml
+
+- name: check that ansible_parent_role_names is normally unset when not included/imported (after including other role)
+ assert:
+ that:
+ - "ansible_parent_role_names is undefined"
+ - "ansible_parent_role_paths is undefined"
+
+- name: ansible_parent_role_names - test functionality by importing another role
+ import_role:
+ name: include_parent_role_vars
+ tasks_from: included_by_other_role.yml
+
+- name: check that ansible_parent_role_names is normally unset when not included/imported (after importing other role)
+ assert:
+ that:
+ - "ansible_parent_role_names is undefined"
+ - "ansible_parent_role_paths is undefined"
+
+- name: ansible_parent_role_names - test functionality by including another role
+ include_role:
+ name: include_parent_role_vars
+
+- name: check that ansible_parent_role_names is normally unset when not included/imported (after both import and inlcude)
+ assert:
+ that:
+ - "ansible_parent_role_names is undefined"
+ - "ansible_parent_role_paths is undefined"
+
+- name: ansible_parent_role_names - test functionality by importing another role
+ import_role:
+ name: include_parent_role_vars
diff --git a/test/integration/targets/special_vars/templates/foo.j2 b/test/integration/targets/special_vars/templates/foo.j2
new file mode 100644
index 0000000..0f6db2a
--- /dev/null
+++ b/test/integration/targets/special_vars/templates/foo.j2
@@ -0,0 +1,7 @@
+test_template_host: "{{template_host}}"
+test_template_path: "{{template_path}}"
+test_template_mtime: "{{template_mtime}}"
+test_template_uid: "{{template_uid}}"
+test_template_fullpath: "{{template_fullpath}}"
+test_template_run_date: "{{template_run_date}}"
+test_ansible_managed: "{{ansible_managed}}"
diff --git a/test/integration/targets/special_vars/vars/main.yml b/test/integration/targets/special_vars/vars/main.yml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/integration/targets/special_vars/vars/main.yml
diff --git a/test/integration/targets/special_vars_hosts/aliases b/test/integration/targets/special_vars_hosts/aliases
new file mode 100644
index 0000000..498fedd
--- /dev/null
+++ b/test/integration/targets/special_vars_hosts/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group4
+context/controller
diff --git a/test/integration/targets/special_vars_hosts/inventory b/test/integration/targets/special_vars_hosts/inventory
new file mode 100644
index 0000000..8d69e57
--- /dev/null
+++ b/test/integration/targets/special_vars_hosts/inventory
@@ -0,0 +1,3 @@
+successful ansible_connection=local ansible_host=127.0.0.1 ansible_python_interpreter="{{ ansible_playbook_python }}"
+failed ansible_connection=local ansible_host=127.0.0.1 ansible_python_interpreter="{{ ansible_playbook_python }}"
+unreachable ansible_connection=ssh ansible_host=127.0.0.1 ansible_port=1011 # IANA Reserved port
diff --git a/test/integration/targets/special_vars_hosts/playbook.yml b/test/integration/targets/special_vars_hosts/playbook.yml
new file mode 100644
index 0000000..e3d9e43
--- /dev/null
+++ b/test/integration/targets/special_vars_hosts/playbook.yml
@@ -0,0 +1,53 @@
+---
+- hosts: all
+ gather_facts: no
+ tasks:
+ - name: test magic vars for hosts without any failed/unreachable (no serial)
+ assert:
+ that:
+ - ansible_play_batch | length == 3
+ - ansible_play_hosts | length == 3
+ - ansible_play_hosts_all | length == 3
+ run_once: True
+
+ - ping:
+ failed_when: "inventory_hostname == 'failed'"
+
+ - meta: clear_host_errors
+
+- hosts: all
+ gather_facts: no
+ tasks:
+ - name: test host errors were cleared
+ assert:
+ that:
+ - ansible_play_batch | length == 3
+ - ansible_play_hosts | length == 3
+ - ansible_play_hosts_all | length == 3
+ run_once: True
+
+ - ping:
+ failed_when: "inventory_hostname == 'failed'"
+
+ - name: test magic vars exclude failed/unreachable hosts
+ assert:
+ that:
+ - ansible_play_batch | length == 1
+ - ansible_play_hosts | length == 1
+ - "ansible_play_batch == ['successful']"
+ - "ansible_play_hosts == ['successful']"
+ - ansible_play_hosts_all | length == 3
+ run_once: True
+
+- hosts: all
+ gather_facts: no
+ tasks:
+ - name: test failed/unreachable persists between plays
+ assert:
+ that:
+ - ansible_play_batch | length == 1
+ - ansible_play_hosts | length == 1
+ - "ansible_play_batch == ['successful']"
+ - "ansible_play_hosts == ['successful']"
+ - ansible_play_hosts_all | length == 3
+ run_once: True
diff --git a/test/integration/targets/special_vars_hosts/runme.sh b/test/integration/targets/special_vars_hosts/runme.sh
new file mode 100755
index 0000000..81c1d9b
--- /dev/null
+++ b/test/integration/targets/special_vars_hosts/runme.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+set -eux
+
+ansible-playbook -i ./inventory playbook.yml "$@" | tee out.txt
+grep 'unreachable=2' out.txt
+grep 'failed=2' out.txt