summaryrefslogtreecommitdiff
path: root/test/integration/roles/test_add_host/tasks/main.yml
blob: cafd6bd4eb61ddab290f4ae3b5b092a6fb165211 (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
# test code for the add_host action
# (c) 2015, Matt Davis <mdavis@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: add a host to the runtime inventory
  add_host:
    name: newdynamichost
    groups: newdynamicgroup
    a_var: from add_host

- debug: msg={{hostvars['newdynamichost'].group_names}}

- name: ensure that dynamically-added host is visible via hostvars, groups, etc (there are several caches that could break this)
  assert:
    that:
    - hostvars['bogushost'] is not defined # there was a bug where an undefined host was a "type" instead of an instance- ensure this works before we rely on it
    - hostvars['newdynamichost'] is defined
    - hostvars['newdynamichost'].group_names is defined
    - "'newdynamicgroup' in hostvars['newdynamichost'].group_names"
    - hostvars['newdynamichost']['bogusvar'] is not defined
    - hostvars['newdynamichost']['a_var'] is defined
    - hostvars['newdynamichost']['a_var'] == 'from add_host'
    - groups['bogusgroup'] is not defined # same check as above to ensure that bogus groups are undefined...
    - groups['newdynamicgroup'] is defined
    - "'newdynamichost' in groups['newdynamicgroup']"