Created
June 21, 2023 16:21
-
-
Save Alveel/9454bc6c49ea76c3a27a775b9bbb87d6 to your computer and use it in GitHub Desktop.
Ansible async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# 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