Skip to content

Commit f028993

Browse files
committed
Don't execute deployment roles if packages are not installed
When running the deployment roles, if packages are not installed, an error of a missing module is shown, which is confusing to users. By ensuring that either installation or uninstallation only work if a minimal set of tools is available allows to provide a meaningful message and let users act on the environment. For installation, if ipa-server/client-install is not available, the installation is aborted with a meaningful error. For uninstallation, we assume that IPA is not installed and gently finish the process with no errors. Signed-off-by: Rafael Guterres Jeffman <rjeffman@redhat.com>
1 parent 91d818b commit f028993

5 files changed

Lines changed: 65 additions & 13 deletions

File tree

roles/ipaclient/tasks/install.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
state: present
88
when: ipaclient_install_packages | bool
99

10+
- name: Check package availability
11+
when: not (ipaclient_install_packages | bool)
12+
block:
13+
- name: Install - Check package installation
14+
ansible.builtin.stat:
15+
path: /usr/sbin/ipa-client-install
16+
register: __ipa_client_install_available
17+
18+
- name: Install - Abort installation due to missing packages
19+
ansible.builtin.fail:
20+
msg: "IPA client packages missing or corrupted"
21+
when: not __ipa_client_install_available.stat.exists
22+
1023
- name: Install - Set ipaclient_servers
1124
ansible.builtin.set_fact:
1225
ipaclient_servers: "{{ groups['ipaservers'] | list }}"
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
---
22
# tasks to uninstall IPA client
33

4-
- name: Uninstall - Uninstall IPA client
5-
ansible.builtin.command: >
6-
/usr/sbin/ipa-client-install
7-
--uninstall
8-
-U
9-
register: uninstall
10-
# 2 means that uninstall failed because IPA client was not configured
11-
failed_when: uninstall.rc != 0 and uninstall.rc != 2
12-
changed_when: uninstall.rc == 0
4+
- name: Uninstall - Check if ipa-client-install is present
5+
ansible.builtin.stat:
6+
path: /usr/sbin/ipa-client-install
7+
register: __ipa_client_install_available
138

14-
- name: Uninstall - Unconfigure DNS resolver
15-
ipaclient_configure_dns_resolver:
16-
state: absent
17-
when: ipaclient_cleanup_dns_resolver | bool
9+
- name: Uninstall - Perform uninstall
10+
when: __ipa_client_install_available.stat.exists
11+
block:
12+
- name: Uninstall - Uninstall IPA client
13+
ansible.builtin.command: >
14+
/usr/sbin/ipa-client-install
15+
--uninstall
16+
-U
17+
register: uninstall
18+
# 2 means that uninstall failed because IPA client was not configured
19+
failed_when: uninstall.rc != 0 and uninstall.rc != 2
20+
changed_when: uninstall.rc == 0
21+
22+
- name: Uninstall - Unconfigure DNS resolver
23+
ipaclient_configure_dns_resolver:
24+
state: absent
25+
when: ipaclient_cleanup_dns_resolver | bool

roles/ipareplica/tasks/install.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
state: present
2929
when: ipareplica_setup_firewalld | bool
3030

31+
- name: Check package availability
32+
when: not (ipareplica_install_packages | bool)
33+
block:
34+
- name: Install - Check package installation
35+
ansible.builtin.stat:
36+
path: /usr/sbin/ipa-server-install
37+
register: __ipa_replica_install_available
38+
39+
- name: Install - Abort installation due to missing packages
40+
ansible.builtin.fail:
41+
msg: "IPA server packages missing or corrupted"
42+
when: not __ipa_replica_install_available.stat.exists
43+
3144
- name: Firewall configuration
3245
when: ipareplica_setup_firewalld | bool
3346
block:

roles/ipaserver/tasks/install.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
state: present
2828
when: ipaserver_setup_firewalld | bool
2929

30+
- name: Check package availability
31+
when: not (ipaserver_install_packages | bool)
32+
block:
33+
- name: Install - Check package installation
34+
ansible.builtin.stat:
35+
path: /usr/sbin/ipa-server-install
36+
register: __ipa_server_install_available
37+
38+
- name: Install - Abort installation due to missing packages
39+
ansible.builtin.fail:
40+
msg: "IPA server packages missing or corrupted"
41+
when: not __ipa_server_install_available.stat.exists
3042

3143
- name: Install - Firewall configuration
3244
when: ipaserver_setup_firewalld | bool

roles/ipaserver/tasks/uninstall.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
when: ipaserver_remove_on_server is defined or
4343
result_get_connected_server.server is defined
4444

45+
- name: Uninstall - Check if ipa-server-install is present
46+
ansible.builtin.stat:
47+
path: /usr/sbin/ipa-server-install
48+
register: __ipa_server_install_available
49+
4550
- name: Uninstall - Uninstall IPA server
4651
ansible.builtin.command: >
4752
/usr/sbin/ipa-server-install
@@ -54,3 +59,4 @@
5459
# 1 means that uninstall failed because IPA server was not configured
5560
failed_when: uninstall.rc != 0 and uninstall.rc != 1
5661
changed_when: uninstall.rc == 0
62+
when: __ipa_server_install_available.stat.exists

0 commit comments

Comments
 (0)