Skip to content

Commit

Permalink
feat: rework ansible host updates in HBI
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Jerome <[email protected]>
  • Loading branch information
DuckBoss committed Dec 20, 2023
1 parent 45ea659 commit 0b9ab6d
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions tasks/insights-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,51 @@
insertafter: "#auto_update"
line: auto_update={{ rhc_insights.autoupdate | d(true) | bool }}

- name: Configure ansible host
- name: Check ansible host in insights-client config
when:
- rhc_insights.ansible_host is defined
- not rhc_insights.ansible_host is none
- rhc_insights.ansible_host != omit
lineinfile:
path: "{{ __rhc_insights_conf }}"
regexp: "^ansible_host"
insertafter: "#ansible_host"
line: ansible_host={{ rhc_insights.ansible_host }}
register: __insights_ansible_host_configured
regexp: "^ansible_host="
state: "{{ 'present' if rhc_insights.ansible_host != __rhc_state_absent else 'absent' }}"
line: "{{ ('ansible_host='+rhc_insights.ansible_host) if rhc_insights.ansible_host != __rhc_state_absent }}"
check_mode: true
register: __insights_ansible_host_exists

- name: Configure ansible host
when:
- rhc_insights.ansible_host is defined
- not rhc_insights.ansible_host is none
- rhc_insights.ansible_host != omit
- __insights_ansible_host_exists.changed
block:
- name: Update ansible host in insights-client config
lineinfile:
path: "{{ __rhc_insights_conf }}"
regexp: "^ansible_host"
insertafter: "#ansible_host"
line: ansible_host={{ rhc_insights.ansible_host }}
- name: Update ansible host in inventory
shell: insights-client --ansible-host={{ rhc_insights.ansible_host }} & wait
when:
- rhc_insights.ansible_host != __rhc_state_absent

- name: Remove ansible host
lineinfile:
path: "{{ __rhc_insights_conf }}"
regexp: "^ansible_host="
state: absent
when:
- rhc_insights.ansible_host is defined
- rhc_insights.ansible_host == __rhc_state_absent
- __insights_ansible_host_exists.changed
block:
- name: Remove ansible host from insights-client config
lineinfile:
path: "{{ __rhc_insights_conf }}"
regexp: "^ansible_host="
state: absent
- name: Remove ansible host in inventory
shell: insights-client --ansible-host= & wait
register: __insights_ansible_host_removed

- name: Register insights-client
shell: insights-client --register & wait
Expand All @@ -76,7 +101,6 @@
- >-
__insights_tags_added is changed
or __insights_tags_removed is changed
or __insights_ansible_host_configured is changed
changed_when: true

- name: Configure remediation
Expand Down

0 comments on commit 0b9ab6d

Please sign in to comment.