summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/var_templating
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/var_templating')
-rw-r--r--test/integration/targets/var_templating/aliases2
-rw-r--r--test/integration/targets/var_templating/ansible_debug_template.j21
-rw-r--r--test/integration/targets/var_templating/group_vars/all.yml7
-rwxr-xr-xtest/integration/targets/var_templating/runme.sh21
-rw-r--r--test/integration/targets/var_templating/task_vars_templating.yml58
-rw-r--r--test/integration/targets/var_templating/test_connection_vars.yml26
-rw-r--r--test/integration/targets/var_templating/test_vars_with_sources.yml9
-rw-r--r--test/integration/targets/var_templating/undall.yml6
-rw-r--r--test/integration/targets/var_templating/undefined.yml13
-rw-r--r--test/integration/targets/var_templating/vars/connection.yml3
10 files changed, 146 insertions, 0 deletions
diff --git a/test/integration/targets/var_templating/aliases b/test/integration/targets/var_templating/aliases
new file mode 100644
index 0000000..1d28bdb
--- /dev/null
+++ b/test/integration/targets/var_templating/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group5
+context/controller
diff --git a/test/integration/targets/var_templating/ansible_debug_template.j2 b/test/integration/targets/var_templating/ansible_debug_template.j2
new file mode 100644
index 0000000..8fe25f9
--- /dev/null
+++ b/test/integration/targets/var_templating/ansible_debug_template.j2
@@ -0,0 +1 @@
+{{ hello }}
diff --git a/test/integration/targets/var_templating/group_vars/all.yml b/test/integration/targets/var_templating/group_vars/all.yml
new file mode 100644
index 0000000..4eae7c1
--- /dev/null
+++ b/test/integration/targets/var_templating/group_vars/all.yml
@@ -0,0 +1,7 @@
+---
+x: 100
+y: "{{ x }}"
+nested_x:
+ value:
+ x: 100
+nested_y: "{{ nested_x }}"
diff --git a/test/integration/targets/var_templating/runme.sh b/test/integration/targets/var_templating/runme.sh
new file mode 100755
index 0000000..bcf0924
--- /dev/null
+++ b/test/integration/targets/var_templating/runme.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+set -eux
+
+# this should succeed since we override the undefined variable
+ansible-playbook undefined.yml -i inventory -v "$@" -e '{"mytest": False}'
+
+# this should still work, just show that var is undefined in debug
+ansible-playbook undefined.yml -i inventory -v "$@"
+
+# this should work since we dont use the variable
+ansible-playbook undall.yml -i inventory -v "$@"
+
+# test hostvars templating
+ansible-playbook task_vars_templating.yml -v "$@"
+
+# there should be an attempt to use 'sudo' in the connection debug output
+ANSIBLE_BECOME_ALLOW_SAME_USER=true ansible-playbook test_connection_vars.yml -vvvv "$@" | tee /dev/stderr | grep 'sudo \-H \-S'
+
+# smoke test usage of VarsWithSources that is used when ANSIBLE_DEBUG=1
+ANSIBLE_DEBUG=1 ansible-playbook test_vars_with_sources.yml -v "$@"
diff --git a/test/integration/targets/var_templating/task_vars_templating.yml b/test/integration/targets/var_templating/task_vars_templating.yml
new file mode 100644
index 0000000..88e1e60
--- /dev/null
+++ b/test/integration/targets/var_templating/task_vars_templating.yml
@@ -0,0 +1,58 @@
+---
+- hosts: localhost
+ connection: local
+ gather_facts: no
+ tasks:
+ - add_host:
+ name: host1
+ ansible_connection: local
+ ansible_host: 127.0.0.1
+
+- hosts: all
+ gather_facts: no
+ tasks:
+ - debug:
+ msg: "{{ hostvars['host1']['x'] }}"
+ register: x_1
+ - debug:
+ msg: "{{ hostvars['host1']['y'] }}"
+ register: y_1
+ - debug:
+ msg: "{{ hostvars_['x'] }}"
+ vars:
+ hostvars_: "{{ hostvars['host1'] }}"
+ register: x_2
+ - debug:
+ msg: "{{ hostvars_['y'] }}"
+ vars:
+ hostvars_: "{{ hostvars['host1'] }}"
+ register: y_2
+
+ - assert:
+ that:
+ - x_1 == x_2
+ - y_1 == y_2
+ - x_1 == y_1
+
+ - debug:
+ msg: "{{ hostvars['host1']['nested_x']['value'] }}"
+ register: x_1
+ - debug:
+ msg: "{{ hostvars['host1']['nested_y']['value'] }}"
+ register: y_1
+ - debug:
+ msg: "{{ hostvars_['nested_x']['value'] }}"
+ vars:
+ hostvars_: "{{ hostvars['host1'] }}"
+ register: x_2
+ - debug:
+ msg: "{{ hostvars_['nested_y']['value'] }}"
+ vars:
+ hostvars_: "{{ hostvars['host1'] }}"
+ register: y_2
+
+ - assert:
+ that:
+ - x_1 == x_2
+ - y_1 == y_2
+ - x_1 == y_1
diff --git a/test/integration/targets/var_templating/test_connection_vars.yml b/test/integration/targets/var_templating/test_connection_vars.yml
new file mode 100644
index 0000000..2b22eea
--- /dev/null
+++ b/test/integration/targets/var_templating/test_connection_vars.yml
@@ -0,0 +1,26 @@
+---
+- hosts: localhost
+ gather_facts: no
+ vars:
+ my_var:
+ become_method: sudo
+ connection: local
+ become: 1
+ tasks:
+
+ - include_vars: "./vars/connection.yml"
+
+ - command: whoami
+ ignore_errors: yes
+ register: result
+ failed_when: result is not success and (result.module_stderr is defined or result.module_stderr is defined)
+
+ - assert:
+ that:
+ - "'sudo' in result.module_stderr"
+ when: result is not success and result.module_stderr is defined
+
+ - assert:
+ that:
+ - "'Invalid become method specified' not in result.msg"
+ when: result is not success and result.msg is defined
diff --git a/test/integration/targets/var_templating/test_vars_with_sources.yml b/test/integration/targets/var_templating/test_vars_with_sources.yml
new file mode 100644
index 0000000..0b8c990
--- /dev/null
+++ b/test/integration/targets/var_templating/test_vars_with_sources.yml
@@ -0,0 +1,9 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - template:
+ src: ansible_debug_template.j2
+ dest: "{{ output_dir }}/ansible_debug_templated.txt"
+ vars:
+ output_dir: "{{ lookup('env', 'OUTPUT_DIR') }}"
+ hello: hello
diff --git a/test/integration/targets/var_templating/undall.yml b/test/integration/targets/var_templating/undall.yml
new file mode 100644
index 0000000..9ea9f1d
--- /dev/null
+++ b/test/integration/targets/var_templating/undall.yml
@@ -0,0 +1,6 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - debug:
+ vars:
+ mytest: '{{ und }}'
diff --git a/test/integration/targets/var_templating/undefined.yml b/test/integration/targets/var_templating/undefined.yml
new file mode 100644
index 0000000..cf083d5
--- /dev/null
+++ b/test/integration/targets/var_templating/undefined.yml
@@ -0,0 +1,13 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: show defined/undefined var
+ debug: var=mytest
+ vars:
+ mytest: '{{ und }}'
+ register: var_undefined
+
+ - name: ensure either mytest is defined or debug finds it to be undefined
+ assert:
+ that:
+ - mytest is defined or 'VARIABLE IS NOT DEFINED!' in var_undefined['mytest']
diff --git a/test/integration/targets/var_templating/vars/connection.yml b/test/integration/targets/var_templating/vars/connection.yml
new file mode 100644
index 0000000..263929a
--- /dev/null
+++ b/test/integration/targets/var_templating/vars/connection.yml
@@ -0,0 +1,3 @@
+ansible_become: "{{ my_var.become }}"
+ansible_become_method: "{{ my_var.become_method }}"
+ansible_connection: "{{ my_var.connection }}"