Marcos Entenza
2019-12-13 5a9976fe0206c34751c81b29bcdb340dd4354e42
Modidy RHSM playbook and fix issues for RHEL 8 based bastion (#927)

* Modidy RHSM plays for repositories role to make it idempotent and enable pool ids

* Add suggested changes
2 files modified
52 ■■■■■ changed files
ansible/roles/bastion/tasks/main.yml 1 ●●●● patch | view | raw | blame | history
ansible/roles/set-repositories/tasks/rhn-repos.yml 51 ●●●●● patch | view | raw | blame | history
ansible/roles/bastion/tasks/main.yml
@@ -75,6 +75,7 @@
    state: present
    chain: INPUT
    jump: ACCEPT
  ignore_errors: yes
- name: Stat /etc/sysconfig/iptables
  stat:
ansible/roles/set-repositories/tasks/rhn-repos.yml
@@ -1,41 +1,26 @@
# vim: set ft=ansible:
---
- name: Force unregister before register
  redhat_subscription:
    state: absent
  register: task_result
  until: task_result | succeeded
  retries: 10
  delay: 5
- name: register node with subscription-manager
- name: Force unregister before register
  command: "{{ item }}"
  args:
    warn: False
  with_items:
  - 'subscription-manager clean'
  - 'subscription-manager remove --all'
  - 'yum remove -y "katello-ca-consumer-*"'
- name: 'Register system using Red Hat Subscription Manager'
  redhat_subscription:
    state: present
    username: "{{ rhel_subscription_user }}"
    password: "{{ rhel_subscription_pass }}"
    autosubscribe: false
  register: task_result
  until: task_result | succeeded
  retries: 10
  delay: 5
    pool_ids: "{{ rhsm_pool_ids }}"
    auto_attach: false
# TODO: should take pool ids from a var
- name: get product pool id
  shell: /usr/bin/subscription-manager list --all --available --matches="*{{rhn_pool_id_string}}*" | awk '/Pool ID/ {print $3}' | head -1
  # command: subscription-manager list --all --available --matches="OpenShift Container Platform" | awk '/Pool ID/ {print $3}' | head -1
  register: pool_id
  until: pool_id | succeeded
  retries: 10
  delay: 5
- name: attach host to subscription pool
  shell: /usr/bin/subscription-manager attach --pool={{ pool_id.stdout }}
  register: task_result
  until: task_result.rc == 0
  retries: 10
  delay: 5
- name: enable repos for rhel
  command: subscription-manager repos --enable "{{ item }}"
  with_items:
    - '{{ rhel_repos }}'
- name: "Run 'subscription-manager to disable/enable repos"
  command: >-
    subscription-manager repos {% for repo in rhel_repos %}
    --enable={{ repo }}
    {% endfor %}
  when: rhel_repos | default([]) | length > 0