summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/delegate_to/test_delegate_to.yml
blob: dcfa9d0351bd1cdd61459527c2758b83eed65d0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
- hosts: testhost3
  vars:
    - template_role: ./roles/test_template
    - output_dir: "{{ playbook_dir }}"
    - templated_var: foo
    - templated_dict: { 'hello': 'world' }
  tasks:
    - name: Test no delegate_to
      setup:
      register: setup_results

    - assert:
        that:
          - '"127.0.0.3" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'

    - name: Test delegate_to with host in inventory
      setup:
      register: setup_results
      delegate_to: testhost4

    - debug: var=setup_results

    - assert:
        that:
          - '"127.0.0.4" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'

    - name: Test delegate_to with host not in inventory
      setup:
      register: setup_results
      delegate_to: 127.0.0.254

    - assert:
        that:
          - '"127.0.0.254" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'
#
# Smoketest some other modules do not error as a canary
#
    - name: Test file works with delegate_to and a host in inventory
      file: path={{ output_dir }}/foo.txt mode=0644 state=touch
      delegate_to: testhost4

    - name: Test file works with delegate_to and a host not in inventory
      file: path={{ output_dir }}/tmp.txt mode=0644 state=touch
      delegate_to: 127.0.0.254

    - name: Test template works with delegate_to and a host in inventory
      template: src={{ template_role }}/templates/foo.j2 dest={{ output_dir }}/foo.txt
      delegate_to: testhost4

    - name: Test template works with delegate_to and a host not in inventory
      template: src={{ template_role }}/templates/foo.j2 dest={{ output_dir }}/foo.txt
      delegate_to: 127.0.0.254

    - name: remove test file
      file: path={{ output_dir }}/foo.txt state=absent

    - name: remove test file
      file: path={{ output_dir }}/tmp.txt state=absent


- name: verify delegation with per host vars
  hosts: testhost6
  gather_facts: yes
  tasks:
    - debug: msg={{ansible_facts['env']}}

    - name: ensure normal facts still work as expected
      assert:
        that:
          - '"127.0.0.3" in ansible_facts["env"]["SSH_CONNECTION"]'

    - name: Test delegate_to with other host defined using same named var
      setup:
      register: setup_results
      delegate_to: testhost7

    - debug: msg={{setup_results.ansible_facts.ansible_env}}

    - name: verify ssh plugin resolves variable for ansible_host correctly
      assert:
        that:
          - '"127.0.0.4" in setup_results.ansible_facts.ansible_env["SSH_CONNECTION"]'