Debian Codegraph @

test/integration/targets/delegate_to/test_delegate_to.yml

raw
1 - hosts: testhost3
2 vars:
3 template_role: ./roles/test_template
4 output_dir: "{{ playbook_dir }}"
5 templated_var: foo
6 templated_dict: { 'hello': 'world' }
7 tasks:
8 - name: Test no delegate_to
9 setup:
10 register: setup_results
11
12 - assert:
13 that:
14 - '"127.0.0.3" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'
15
16 - name: Test delegate_to with host in inventory
17 setup:
18 register: setup_results
19 delegate_to: testhost4
20
21 - debug: var=setup_results
22
23 - assert:
24 that:
25 - '"127.0.0.4" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'
26
27 - name: Test delegate_to with host not in inventory
28 setup:
29 register: setup_results
30 delegate_to: 127.0.0.254
31
32 - assert:
33 that:
34 - '"127.0.0.254" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'
35 #
36 # Smoketest some other modules do not error as a canary
37 #
38 - name: Test file works with delegate_to and a host in inventory
39 file: path={{ output_dir }}/foo.txt mode=0644 state=touch
40 delegate_to: testhost4
41
42 - name: Test file works with delegate_to and a host not in inventory
43 file: path={{ output_dir }}/tmp.txt mode=0644 state=touch
44 delegate_to: 127.0.0.254
45
46 - name: Test template works with delegate_to and a host in inventory
47 template: src={{ template_role }}/templates/foo.j2 dest={{ output_dir }}/foo.txt
48 delegate_to: testhost4
49
50 - name: Test template works with delegate_to and a host not in inventory
51 template: src={{ template_role }}/templates/foo.j2 dest={{ output_dir }}/foo.txt
52 delegate_to: 127.0.0.254
53
54 - name: remove test file
55 file: path={{ output_dir }}/foo.txt state=absent
56
57 - name: remove test file
58 file: path={{ output_dir }}/tmp.txt state=absent
59
60 - name: Use omit to thwart delegation
61 ping:
62 delegate_to: "{{ jenkins_install_key_on|default(omit) }}"
63 register: d_omitted
64
65 - name: Use literal empty delegation should fail
66 ping:
67 delegate_to: ""
68 when: false
69 ignore_errors: true
70 register: d_literal_empty
71
72 - name: Use empty to thwart delegation should fail
73 ping:
74 delegate_to: "{{ jenkins_install_key_on }}"
75 when: false
76 vars:
77 jenkins_install_key_on: ''
78 ignore_errors: true
79 register: d_empty
80
81 - name: Ensure delegation validation behaved as expected
82 assert:
83 that:
84 - d_omitted is success
85 - d_literal_empty is failed
86 - d_literal_empty.msg is contains('Empty hostname produced from delegate_to')
87 - d_empty is failed
88 - d_empty.msg is contains('Empty hostname produced from delegate_to')
89
90 - name: verify delegation with per host vars
91 hosts: testhost6
92 gather_facts: yes
93 tasks:
94 - debug: msg={{ansible_facts['env']}}
95
96 - name: ensure normal facts still work as expected
97 assert:
98 that:
99 - '"127.0.0.3" in ansible_facts["env"]["SSH_CONNECTION"]'
100
101 - name: Test delegate_to with other host defined using same named var
102 setup:
103 register: setup_results
104 delegate_to: testhost7
105
106 - debug: msg={{setup_results.ansible_facts.ansible_env}}
107
108 - name: verify ssh plugin resolves variable for ansible_host correctly
109 assert:
110 that:
111 - '"127.0.0.4" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'