ansible: Register SLES nodes if necessary
authorKienan Stewart <kstewart@efficios.com>
Wed, 31 Jan 2024 15:19:15 +0000 (10:19 -0500)
committerKienan Stewart <kstewart@efficios.com>
Fri, 2 Feb 2024 14:07:03 +0000 (09:07 -0500)
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Change-Id: Iae950177ebddf2ecec67f9f719d088051cdaee2f

automation/ansible/roles/common/tasks/setup-Suse.yml

index da745d855bd913359c299e0bcd0f7ab722b39da7..23b681b9de3332908e58ea33dd5800ced45d5c2e 100644 (file)
@@ -1,4 +1,31 @@
 ---
+- name: Register with SLES
+  when: ansible_distribution == 'SLES'
+  block:
+    - name: Check registration
+      ansible.builtin.command:
+        argv: ['SUSEConnect', '--status']
+      register: registration_status
+      ignore_errors: true
+    - name: Cleanup registration
+      when: registration_status.rc != 0
+      ansible.builtin.command:
+        argv[ 'SUSEConnect', '--cleanup']
+    - ansible.builtin.set_fact:
+        registration_status_data: "{{registration_status.stdout|ansible.builtin.from_json|first}}"
+    - name: Get key from host environment
+      when: registration_status_data['status'] == 'Not Registered'
+      ansible.builtin.set_fact:
+        registration_key: "{{lookup('ansible.builtin.env', 'SLES_REGISTRATION_CODE_' + ansible_architecture, default='')}}"
+    - name: Get key from bitwarden
+      when: registration_key|default('') == '' and registration_status_data['status'] == 'Not Registered'
+      ansible.builtin.set_fact:
+        registration_key: "{{lookup('community.general.bitwarden', 'bec75018-99e8-4064-9cd9-addd011947e5', search='id', field='SLES_REGISTRATION_CODE_' +ansible_architecture)[0]}}"
+    - name: Perform registration
+      when: registration_status_data['status'] == 'Not Registered'
+      ansible.builtin.command:
+        argv: ['SUSEConnect', '-r', "{{registration_key}}"]
+
 - name: Connect SLES Repo
   when: ansible_distribution == 'SLES'
   ansible.builtin.command:
This page took 0.023835 seconds and 4 git commands to generate.