--- - name: Setze Variablen für SUSE Manager API set_fact: suma_api_url: "{{ suma_api_url }}" suma_api_user: "{{ suma_api_user }}" suma_api_pass: "{{ suma_api_pass }}" - name: Hole System-ID aus SUSE Manager uri: url: "{{ suma_api_url }}" method: POST body_format: json headers: Content-Type: application/json body: | { "method": "auth.login", "params": ["{{ suma_api_user }}", "{{ suma_api_pass }}"], "id": 1 } validate_certs: no register: suma_api_login ignore_errors: true - name: Logge Fehler bei API-Login copy: content: "API-Login-Fehler: {{ suma_api_login.msg | default('Unbekannter Fehler') }}" dest: "{{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_api_login.failed - name: Breche Playbook ab, wenn API-Login fehlschlägt fail: msg: "SUSE Manager API-Login fehlgeschlagen! Siehe Log: {{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_api_login.failed - name: Setze Session-ID set_fact: suma_session: "{{ suma_api_login.json.result }}" - name: Suche System-ID anhand Hostname uri: url: "{{ suma_api_url }}" method: POST body_format: json headers: Content-Type: application/json body: | { "method": "system.getId", "params": ["{{ suma_session }}", "{{ inventory_hostname }}"], "id": 2 } validate_certs: no register: suma_system_id ignore_errors: true - name: Logge Fehler bei System-ID-Suche copy: content: "System-ID-Fehler: {{ suma_system_id.msg | default('Unbekannter Fehler') }}" dest: "{{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_system_id.failed - name: Breche Playbook ab, wenn System-ID nicht gefunden fail: msg: "System-ID nicht gefunden! Siehe Log: {{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_system_id.failed - name: Suche Channel-ID anhand Ziel-CLM-Version uri: url: "{{ suma_api_url }}" method: POST body_format: json headers: Content-Type: application/json body: | { "method": "channel.software.listAllChannels", "params": ["{{ suma_session }}"], "id": 3 } validate_certs: no register: suma_channels ignore_errors: true - name: Logge Fehler bei Channel-Suche copy: content: "Channel-Such-Fehler: {{ suma_channels.msg | default('Unbekannter Fehler') }}" dest: "{{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_channels.failed - name: Breche Playbook ab, wenn Channel-Suche fehlschlägt fail: msg: "Channel-Suche fehlgeschlagen! Siehe Log: {{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_channels.failed - name: Finde Channel-ID für Ziel-CLM-Version set_fact: target_channel_label: "{{ item.label }}" loop: "{{ suma_channels.json.result }}" when: item.name is search(target_clm_version) loop_control: label: "{{ item.label }}" - name: Breche ab, wenn kein passender Channel gefunden wurde fail: msg: "Kein passender CLM-Channel für '{{ target_clm_version }}' gefunden!" when: target_channel_label is not defined - name: Weise System dem Channel zu uri: url: "{{ suma_api_url }}" method: POST body_format: json headers: Content-Type: application/json body: | { "method": "system.setBaseChannel", "params": ["{{ suma_session }}", {{ suma_system_id.json.result[0].id }}, "{{ target_channel_label }}"], "id": 4 } validate_certs: no register: suma_assign_result ignore_errors: true - name: Logge Fehler bei Channel-Zuweisung copy: content: "Channel-Zuweisungs-Fehler: {{ suma_assign_result.msg | default('Unbekannter Fehler') }}" dest: "{{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_assign_result.failed - name: Breche Playbook ab, wenn Channel-Zuweisung fehlschlägt fail: msg: "Channel-Zuweisung fehlgeschlagen! Siehe Log: {{ log_dir }}/suma_api_error_{{ inventory_hostname }}.log" when: suma_assign_result.failed - name: Logout von der SUSE Manager API uri: url: "{{ suma_api_url }}" method: POST body_format: json headers: Content-Type: application/json body: | { "method": "auth.logout", "params": ["{{ suma_session }}"], "id": 5 } validate_certs: no when: suma_session is defined