|
27 | 27 | requirements: |
28 | 28 | - pcs-0.10.8 or newer installed on managed nodes |
29 | 29 | - pcs-0.10.8 or newer for exporting corosync configuration |
| 30 | + - python3-firewall for exporting ha_cluster_manage_firewall |
| 31 | + - python3-policycoreutils for exporting ha_cluster_manage_selinux |
30 | 32 | - python 3.6 or newer |
31 | 33 | """ |
32 | 34 |
|
|
51 | 53 | - Following variables are present in the output |
52 | 54 | - ha_cluster_enable_repos |
53 | 55 | - ha_cluster_enable_repos_resilient_storage |
| 56 | + - ha_cluster_manage_firewall |
| 57 | + - ha_cluster_manage_selinux |
54 | 58 | - ha_cluster_cluster_present |
55 | 59 | - ha_cluster_start_on_boot |
56 | 60 | - ha_cluster_install_cloud_agents |
|
77 | 81 | - ha_cluster_fence_virt_key_src |
78 | 82 | - ha_cluster_pcsd_public_key_src |
79 | 83 | - ha_cluster_pcsd_private_key_src |
| 84 | + - ha_cluster_pcsd_certificates |
80 | 85 | - ha_cluster_regenerate_keys |
81 | 86 | - HORIZONTALLINE |
82 | 87 | """ |
|
88 | 93 | # pylint: disable=no-name-in-module |
89 | 94 | from ansible.module_utils.ha_cluster_lsr.info import exporter, loader |
90 | 95 |
|
| 96 | +try: |
| 97 | + # firewall module doesn't provide type hints |
| 98 | + from firewall.client import FirewallClient # type:ignore |
| 99 | + |
| 100 | + HAS_FIREWALL = True |
| 101 | +except ImportError: |
| 102 | + # create the class so it can be replaced by a mock in unit tests |
| 103 | + class FirewallClient: # type: ignore |
| 104 | + # pylint: disable=missing-class-docstring |
| 105 | + # pylint: disable=too-few-public-methods |
| 106 | + pass |
| 107 | + |
| 108 | + HAS_FIREWALL = False |
| 109 | + |
| 110 | +try: |
| 111 | + # selinux module doesn't provide type hints |
| 112 | + from seobject import portRecords as SelinuxPortRecords # type: ignore |
| 113 | + |
| 114 | + HAS_SELINUX = True |
| 115 | +except ImportError: |
| 116 | + # create the class so it can be replaced by a mock in unit tests |
| 117 | + class SelinuxPortRecords: # type: ignore |
| 118 | + # pylint: disable=missing-class-docstring |
| 119 | + # pylint: disable=too-few-public-methods |
| 120 | + pass |
| 121 | + |
| 122 | + HAS_SELINUX = False |
| 123 | + |
91 | 124 |
|
92 | 125 | def get_cmd_runner(module: AnsibleModule) -> loader.CommandRunner: |
93 | 126 | """ |
@@ -129,6 +162,29 @@ def export_os_configuration(module: AnsibleModule) -> Dict[str, Any]: |
129 | 162 | exporter.export_install_cloud_agents(installed_packages) |
130 | 163 | ) |
131 | 164 |
|
| 165 | + if HAS_FIREWALL: |
| 166 | + fw_client = FirewallClient() |
| 167 | + fw_config = loader.get_firewall_config(fw_client) |
| 168 | + manage_firewall = False |
| 169 | + if fw_config is not None: |
| 170 | + manage_firewall = exporter.export_manage_firewall(fw_config) |
| 171 | + result["ha_cluster_manage_firewall"] = manage_firewall |
| 172 | + |
| 173 | + # ha_cluster_manage_selinux is irrelevant when running the role if |
| 174 | + # ha_cluster_manage_firewall is not True |
| 175 | + if HAS_SELINUX and manage_firewall: |
| 176 | + selinux_ports = SelinuxPortRecords() |
| 177 | + ha_ports_firewall = loader.get_firewall_ha_cluster_ports(fw_client) |
| 178 | + ha_ports_selinux = loader.get_selinux_ha_cluster_ports( |
| 179 | + selinux_ports |
| 180 | + ) |
| 181 | + if ha_ports_firewall is not None and ha_ports_selinux is not None: |
| 182 | + result["ha_cluster_manage_selinux"] = ( |
| 183 | + exporter.export_manage_selinux( |
| 184 | + ha_ports_firewall, ha_ports_selinux |
| 185 | + ) |
| 186 | + ) |
| 187 | + |
132 | 188 | return result |
133 | 189 |
|
134 | 190 |
|
|
0 commit comments