-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubscribe_system_to_sat6.yml
174 lines (144 loc) · 4.97 KB
/
subscribe_system_to_sat6.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
---
- hosts: all
vars_files:
- ./vars.yml
- ./passwd.yml
tasks:
- name: Deploy SSH public key for the foreman-proxy user
authorized_key:
key: "{{ lookup('file', '/usr/share/foreman-proxy/.ssh/id_rsa_foreman_proxy.pub') }}"
user: root
state: present
- name: "Ensure Subscription Manager is installed"
shell: rpm -qi subscription-manager
ignore_errors: True
- name: "Check if the system is registered to a Sat5"
stat:
path: /etc/sysconfig/rhn/systemid
register: stat_result
- name: "Backup /etc/sysconfig/rhn/systemid"
copy:
remote_src=true
src=/etc/sysconfig/rhn/systemid
dest=/etc/sysconfig/rhn/systemid.backup
when: stat_result.stat.exists == true
- name: "Check if system is subscribed to Sat6 or CDN"
shell: subscription-manager status
register: subs
# ignore_errors: True
changed_when: subs.rc == 2000
failed_when: subs.rc == 2000
- name: "Unregister from old Satellite 6 or Red Hat CDN, skip if Sat5 registered or not registred at all"
redhat_subscription:
state: absent
when: stat_result.stat.exists == False or subs.rc == 0
- name: "Check for existing katello-ca-consumer package, remove it when it exist"
shell: rpm -e $(rpm -qa|grep katello-ca-consumer)
ignore_errors: true
- name: "Check if /etc/yum/pluginconf.d/rhnplugin.conf exists"
stat:
path: /etc/yum/pluginconf.d/rhnplugin.conf
register: stat_result
- name: "Disable RHN yum Plugin if rhnplugin.conf exists"
lineinfile:
path: /etc/yum/pluginconf.d/rhnplugin.conf
regexp: '^enabled'
line: 'enabled=0'
when: stat_result.stat.exists
- name: "Check if /etc/yum/pluginconf.d/spacewalk.conf exists"
stat:
path: /etc/yum/pluginconf.d/spacewalk.conf
register: stat_result
- name: "Disable RHN yum Plugin if spacewalk.conf exists"
lineinfile:
path: /etc/yum/pluginconf.d/spacewalk.conf
regexp: '^enabled'
line: 'enabled=0'
when: stat_result.stat.exists
- name: "Enable subscription-manager Plugin if its disabled"
lineinfile:
path: /etc/yum/pluginconf.d/subscription-manager.conf
regexp: '^enabled'
line: 'enabled=1'
- name: "Remove line with disable_system_repos if it exists"
lineinfile:
path: /etc/yum/pluginconf.d/subscription-manager.conf
regexp: '^disable_system_repos'
state: absent
- name: "Move /etc/sysconfig/rhn/systemid"
file:
path: /etc/sysconfig/rhn/systemid
state: absent
# - name: remove proxy entry from /etc/yum.conf
# lineinfile:
# path: /etc/yum.conf
# state: absent
# regexp: '^proxy=http://{{ proxy_host }}:{{ proxy_port }}'
# tags:
# - proxy
- name: "Install new Katello Config and Cert RPM"
shell: rpm -i http://{{ capsule_hostname }}/pub/katello-ca-consumer-latest.noarch.rpm
- name: "Run subscription-manager clean for cleanup stuff incl. SSL certs"
shell: subscription-manager clean
- name: Remove proxy host entry from /etc/rhsm/rhsm.conf
lineinfile:
path: /etc/rhsm/rhsm.conf
state: absent
regexp: '^proxy_hostname={ proxy_host }'
when: proxy_host is defined
tags:
- proxy
- name: Remove proxy port entry from /etc/rhsm/rhsm.conf
lineinfile:
path: /etc/rhsm/rhsm.conf
state: absent
regexp: '^proxy_port={ proxy_port }'
when: proxy_port is defined
tags:
- proxy
- name: "Register the machine to Satellite 6"
ignore_errors: true
redhat_subscription:
state: present
activationkey: '{{ activationkey }}'
org_id: '{{ organization }}'
- name: "Run auto-attach as a workaround for a bug"
shell: subscription-manager attach --auto
- name: "Cleanup Yum cache"
shell: yum clean all
- name: "Remove obsolete Yum Cache Directory"
file:
path: /var/cache/yum
state: absent
# This applies only to clients hosted on Azure to be migrated to Satellite
- name: "Check for existing rhui-azure package, remove it when it exist"
package:
name: rhui-azure*
state: absent
ignore_errors: true
- name: "Install the katello-host-tools-tracer package"
package:
name: katello-host-tools-tracer
state: present
- name: "Assign the host to a Hostgroup"
redhat.satellite.host:
username: "{{ sat_user }}"
password: "{{ sat_passwd }}"
server_url: "{{ sat_url }}"
name: "{{ inventory_hostname }}"
hostgroup: "{{ hostgroup }}"
state: present
when: hostgroup is defined
- name: "Trigger Ansible play for the host"
redhat.satellite.job_invocation:
username: "{{ sat_user }}"
password: "{{ sat_passwd }}"
server_url: "{{ sat_url }}"
search_query: "name ^ ({{ inventory_hostname }})"
job_template: "Ansible Roles - Ansible Default"
when: hostgroup is defined
tags: job
# - name: "Install Custom GPG Key"
# rpm_key:
# state: present
# key: http://{{ capsule }}/pub/RPM-GPG-KEY-example