summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/delegate_to/has_hostvars.yml
blob: 9e8926bde8a8f9682deb6594f0b700add68c3ce0 (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
- name: ensure delegated host has hostvars available for resolving connection
  hosts: testhost
  gather_facts: false
  tasks:

    - name: ensure delegated host uses current host as inventory_hostname
      assert:
        that:
          - inventory_hostname == ansible_delegated_vars['testhost5']['inventory_hostname']
      delegate_to: testhost5

    - name: Set info on inventory_hostname
      set_fact:
        login: invaliduser
        mypass: badpassword

    - name: test fakelocal
      command: ls
      ignore_unreachable: True
      ignore_errors: True
      remote_user: "{{ login }}"
      vars:
        ansible_password: "{{ mypass }}"
        ansible_connection: fakelocal
      register: badlogin

    - name: ensure we skipped do to unreachable and not templating error
      assert:
        that:
          - badlogin is unreachable

    - name: delegate but try to use inventory_hostname data directly
      command: ls
      delegate_to: testhost5
      ignore_unreachable: True
      ignore_errors: True
      remote_user: "{{ login }}"
      vars:
        ansible_password: "{{ mypass }}"
      register: badlogin

    - name: ensure we skipped do to unreachable and not templating error
      assert:
        that:
          - badlogin is not unreachable
          - badlogin is failed
          - "'undefined' in badlogin['msg']"

    - name: delegate ls to testhost5 as it uses ssh while testhost is local, but use vars from testhost
      command: ls
      remote_user: "{{ hostvars[inventory_hostname]['login'] }}"
      delegate_to: testhost5
      ignore_unreachable: True
      ignore_errors: True
      vars:
        ansible_password: "{{ hostvars[inventory_hostname]['mypass'] }}"
      register: badlogin

    - name: ensure we skipped do to unreachable and not templating error
      assert:
        that:
          - badlogin is unreachable
          - badlogin is not failed
          - "'undefined' not in badlogin['msg']"