-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.yml
92 lines (82 loc) · 2.83 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
- name: Set tester node
hosts: localhost
tasks:
- when: groups.tester is not defined or groups.tester|length < 1
block:
- name: Add chosen node to tester group
add_host:
name: "{{ install.get('tester', {}).get('node') | default(groups.get('undercloud', [])|first, true) }}"
groups: "tester"
- include_role:
name: inventory-update
vars:
inventory_file_name: 'hosts-test'
- name: add hosts to run the code using ansible-playbook
hosts: localhost
gather_facts: no
tasks:
- name: add the patcher host to the tester group
add_host:
name: "patcher"
groups: "tester"
ansible_ssh_user: "{{ install.host.username }}"
ansible_ssh_host: "{{ install.host.ip }}"
ansible_ssh_private_key_file: "{{ install.host.key_file }}"
when: (install.host is defined) and (install.host.ip is defined) and (install.host.username is defined) and (install.host.key_file is defined)
- name: Patch and repackage components RPM
hosts: "{{ install.pattern | default('tester') }}"
roles:
- { role: setup_repos }
- { role: setup_environment}
- { role: copy_component }
- { role: patch_rpm }
- name: Create tmp directory on a local node and copy RPMs
hosts: localhost
tasks:
- name: Create tmp dir
tempfile:
state: directory
suffix: "{{ ansible_date_time.iso8601 }}"
register: tempdir_1
when: "'undercloud' not in groups['tester'][0]"
- name: Copy RPMs
hosts: "{{ install.pattern | default('tester') }}"
tasks:
- name: Copy RPMs using rsync
synchronize:
src: "/patched_rpms/"
dest: "{{ hostvars['localhost']['tempdir_1'].path }}/"
mode: pull
when: "'undercloud' not in groups['tester'][0]"
- name: Update undercloud node
hosts: tester
become: yes
tasks:
- name: Setup repository in /etc/yum.repos.d
template:
src: 'patched_rpms.j2'
dest: '/etc/yum.repos.d/patched_rpms.repo'
tags: patched-rpms-repo
- name: Copy RPMs to the undercloud if created on an another node
synchronize:
src: "{{ hostvars['localhost']['tempdir_1'].path }}/"
dest: "/patched_rpms"
mode: push
when: "'undercloud' not in groups['tester'][0]"
- name: SELinux - container_file_t - allow containers to read mounted patched_rpms
file:
path: "/patched_rpms"
recurse: yes
setype: container_file_t
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int >= 8 | default(false)
- name: Cleanup
hosts: localhost
tasks:
- name: remove the temporary dir
file:
path: "{{ tempdir_1.path }}"
state: absent
when:
- tempdir_1.path is defined
- "'undercloud' not in groups['tester'][0]"