/
update_inventory.yml
58 lines (54 loc) · 2.07 KB
/
update_inventory.yml
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
- name: Update inventory file after adding Undercloud hypervisors group
hosts: localhost
gather_facts: yes
tasks:
- block:
- name: set undercloud_hypervisors
set_fact:
undercloud_hypervisors: "{{ undercloud_hypervisors|default([]) + [item[1]] }}"
when: ('ansible_ssh_common_args' in hostvars[item[0]]) and (hostvars[item[1]].ansible_host in hostvars[item[0]].ansible_ssh_common_args)
with_nested:
- "{{ groups.undercloud }}"
- "{{ groups.hypervisor }}"
- name: add undercloud_hypervisors group
add_host:
name: "{{ item }}"
groups: "{{ hostvars[item].group_names + ['undercloud_hypervisors'] }}"
with_items: "{{ (undercloud_hypervisors is defined) | ternary(undercloud_hypervisors, []) }}"
- include_role:
name: inventory-update
vars:
inventory_file_name: 'hosts-prov'
when: ((undercloud_hypervisors is defined) and
(undercloud_hypervisors != []))
- name: refresh dynamic inventory
meta: refresh_inventory
when: "'hypervisor' in groups and 'undercloud' in groups"
tags:
- uc_hypervisors
- name: Discover Undercloud's python interpreter
hosts: undercloud
any_errors_fatal: true
gather_facts: no
tags:
- upgrade
- upgrade_repos
- discover_python
tasks:
- block:
- name: Detect python interpreter in Undercloud
raw: 'command -v python /usr/libexec/platform-python'
register: py_interpreter
- name: Gather facts
setup:
vars:
ansible_python_interpreter: "{{ (py_interpreter.stdout_lines[0] | default('python')) | trim }}"
- include_role:
name: inventory-update
apply:
delegate_to: localhost
vars:
inventory_file_name: 'hosts-upgrade'
- name: refresh dynamic inventory
meta: refresh_inventory
when: install.upgrade|default('')