---
-- name: Define common_patterns.
- set_fact:
- common_patterns: "{{ __common_patterns | list }}"
- when: common_patterns is not defined
+- 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'
+ include_role:
+ name: suse
+ tasks_from: product
+ loop: "{{common_sles_connect_repos}}"
+ loop_control:
+ loop_var: 'product'
- name: Ensure common patterns are installed.
zypper: "name={{ common_patterns }} type=pattern state=present update_cache=yes"