Skip to content

Instantly share code, notes, and snippets.

@Alveel
Created June 21, 2023 16:21
Show Gist options
  • Save Alveel/9454bc6c49ea76c3a27a775b9bbb87d6 to your computer and use it in GitHub Desktop.
Save Alveel/9454bc6c49ea76c3a27a775b9bbb87d6 to your computer and use it in GitHub Desktop.
Ansible async
---
# as the subscription manager task is rather slow
- name: Test to see if system is already subscribed
ansible.builtin.command: subscription-manager status
register: rhsm_status
changed_when: false
failed_when: rhsm_status.rc > 1
async: 60 # wait for up to one minute for the task to complete
poll: 4
when: not ansible_check_mode
- name: Register server
community.general.redhat_subscription:
state: present
org_id: "{{ redhat_subscription_organization }}"
activationkey: "{{ redhat_subscription_activation_key }}"
pool_ids: '{{ pool_ids | default(omit) }}'
when:
- not ansible_check_mode
- '"Overall Status: Current" not in rhsm_status["stdout"]'
async: 180 # wait for up to three minutes for the task to complete
poll: 0 # disable polling; fire and forget.
register: subscription_sleeper
- name: Check on RHSM task
ansible.builtin.async_status:
jid: "{{ subscription_sleeper.ansible_job_id }}"
register: subscription_result
retries: 45 # 180 / 4 = 45
delay: 4
until: subscription_result.finished
when:
- not ansible_check_mode
- '"Overall Status: Current" not in rhsm_status["stdout"]'
- name: Enable repositories
community.general.rhsm_repository:
name: "{{ redhat_subscription_repositories }}"
no_log: true # this spams a lot of output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment