|
| 1 | +--- |
| 2 | +# Copyright Red Hat, Inc. |
| 3 | +# All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +- name: Ensure freeipa vm is started and reachable |
| 18 | + vars: |
| 19 | + _cifmw_libvirt_manager_layout: |
| 20 | + vms: |
| 21 | + free-ipas: |
| 22 | + start: true |
| 23 | + disk_file_name: "dummy" |
| 24 | + cifmw_libvirt_manager_all_vms: >- |
| 25 | + {%- set vms = {} -%} |
| 26 | + {%- for vm in _vm_groups['free-ipas'] -%} |
| 27 | + {%- set _ = vms.update({vm: 'free-ipas'}) -%} |
| 28 | + {%- endfor -%} |
| 29 | + {{ vms }} |
| 30 | + ansible_libvirt_pools: {} |
| 31 | + ansible.builtin.include_role: |
| 32 | + name: "libvirt_manager" |
| 33 | + tasks_from: "start_vms.yml" |
| 34 | + apply: |
| 35 | + delegate_to: "{{ cifmw_target_host | default('localhost') }}" |
| 36 | + |
| 37 | +- name: Run prepration tasks on freeipa |
| 38 | + delegate_to: "free-ipa-0" |
| 39 | + vars: |
| 40 | + _freeipa_name: "{{ _vm_groups['free-ipas'] | first }}" |
| 41 | + _freeipa_net: "{{ cifmw_networking_env_definition.instances[_freeipa_name] }}" |
| 42 | + freeipa_ip: "{{ _freeipa_net.networks.ocpbm[ip_version|default('ip_v4')] }}" |
| 43 | + _undercloud_name: "{{ _vm_groups['osp-underclouds'] | first }}" |
| 44 | + _undercloud_net: "{{ cifmw_networking_env_definition.instances[_undercloud_name] }}" |
| 45 | + undercloud_ip: "{{ _undercloud_net.networks.ocpbm[ip_version|default('ip_v4')] }}" |
| 46 | + cloud_domain: "{{ cifmw_adoption_osp_deploy_scenario.cloud_domain }}" |
| 47 | + block: |
| 48 | + - name: Ensure needed logins |
| 49 | + ansible.builtin.include_tasks: login_registries.yml |
| 50 | + args: |
| 51 | + apply: |
| 52 | + delegate_to: "free-ipa-0" |
| 53 | + |
| 54 | + - name: Set hostname to freeipa-0.{{ cloud_domain }} |
| 55 | + become: true |
| 56 | + ansible.builtin.hostname: |
| 57 | + name: "freeipa-0.{{ cloud_domain }}" |
| 58 | + use: "systemd" |
| 59 | + |
| 60 | + - name: Ensure /etc/hosts file correctly maps the FQDN to freeipa IP address |
| 61 | + become: true |
| 62 | + ansible.builtin.lineinfile: |
| 63 | + path: /etc/hosts |
| 64 | + line: "{{ freeipa_ip }} {{ ansible_hostname }}.{{ cloud_domain }} {{ ansible_hostname }}" |
| 65 | + create: true |
| 66 | + state: present |
| 67 | + mode: "0644" |
| 68 | + |
| 69 | + - name: Install FreeIPA server packages |
| 70 | + become: true |
| 71 | + ansible.builtin.package: |
| 72 | + name: |
| 73 | + - ipa-server |
| 74 | + - ipa-server-dns |
| 75 | + - curl |
| 76 | + - iptables |
| 77 | + state: present |
| 78 | + |
| 79 | + - name: Update NSS (required for CA server to launch during deploy) |
| 80 | + become: true |
| 81 | + ansible.builtin.package: |
| 82 | + name: nss |
| 83 | + state: latest # noqa: package-latest |
| 84 | + |
| 85 | + - name: Deploy FreeIPA server |
| 86 | + become: true |
| 87 | + ansible.builtin.command: |
| 88 | + cmd: >- |
| 89 | + ipa-server-install -U |
| 90 | + --hostname freeipa-0.{{ cloud_domain }} |
| 91 | + --realm {{ cloud_domain.upper() }} |
| 92 | + --admin-password {{ cifmw_adoption_osp_deploy_freeipa_admin_password }} |
| 93 | + --ds-password {{ cifmw_adoption_osp_deploy_freeipa_admin_password }} |
| 94 | + --ip-address={{ freeipa_ip }} |
| 95 | + --setup-dns |
| 96 | + --auto-reverse |
| 97 | + --no-dnssec-validation |
| 98 | + --allow-zone-overlap |
| 99 | + --forwarder=192.168.111.1 |
| 100 | +
|
| 101 | + - name: Create systemd resolv.conf |
| 102 | + become: true |
| 103 | + ansible.builtin.copy: |
| 104 | + dest: "/usr/lib/systemd/resolv.conf" |
| 105 | + content: | |
| 106 | + search {{ cloud_domain }} |
| 107 | + nameserver 127.0.0.1 |
| 108 | + mode: '0644' |
| 109 | + |
| 110 | + - name: Create a symbolic link of systemd resolv.conf |
| 111 | + become: true |
| 112 | + ansible.builtin.file: |
| 113 | + src: "/usr/lib/systemd/resolv.conf" |
| 114 | + dest: "/etc/resolv.conf" |
| 115 | + owner: root |
| 116 | + group: root |
| 117 | + state: link |
| 118 | + force: true |
| 119 | + |
| 120 | + - name: Does the DNS ACL exist |
| 121 | + become: true |
| 122 | + ansible.builtin.shell: >- |
| 123 | + ldapsearch -LLL -x -D "cn=Directory Manager" -w {{ cifmw_adoption_osp_deploy_freeipa_admin_password }} -s base |
| 124 | + -b cn=dns,dc={{ cloud_domain.split(".")[0] }},dc={{ cloud_domain.split(".")[1] }} |
| 125 | + aci='*Allow hosts to read DNS A/AAA/CNAME/PTR records*' numSubordinates | |
| 126 | + sed -n 's/^[ \t]*numSubordinates:[ \t]*\(.*\)/\1/p' |
| 127 | + register: dns_aci_count |
| 128 | + ignore_errors: true |
| 129 | + |
| 130 | + - name: Add ACL to allow hosts access to DNS |
| 131 | + become: true |
| 132 | + ansible.builtin.shell: |
| 133 | + cmd: | |
| 134 | + set -o pipefail |
| 135 | + cat << EOF | ldapmodify -x -D "cn=Directory Manager" -w {{ cifmw_adoption_osp_deploy_freeipa_admin_password }} |
| 136 | + dn: cn=dns,dc={{ cloud_domain.split(".")[0] }},dc={{ cloud_domain.split(".")[1] }} |
| 137 | + changetype: modify |
| 138 | + add: aci |
| 139 | + aci: (targetattr = "aaaarecord || arecord || cnamerecord || idnsname || objectclass || ptrrecord")(targetfilter = "(&(objectclass=idnsrecord)(|(aaaarecord=*)(arecord=*)(cnamerecord=*)(ptrrecord=*)(idnsZoneActive=TRUE)))")(version 3.0; acl "Allow hosts to read DNS A/AAA/CNAME/PTR records"; allow (read,search,compare) userdn = "ldap:///fqdn=*,cn=computers,cn=accounts,dc={{ freeipa_domain.split('.')[0] }},dc={{ freeipa_domain.split('.')[1] }}";) |
| 140 | + EOF |
| 141 | + when: dns_aci_count.stdout|default(0)|int == 0 |
| 142 | + |
| 143 | + - name: Update /etc/hosts with undercloud's details |
| 144 | + become: true |
| 145 | + ansible.builtin.lineinfile: |
| 146 | + dest: "/etc/hosts" |
| 147 | + line: "{{ undercloud_ip }} {{ _undercloud_name }}.{{ cloud_domain }} {{ _undercloud_name }}" |
| 148 | + state: present |
| 149 | + |
| 150 | + - name: Ensure DNS query is not blocked by iptables |
| 151 | + become: true |
| 152 | + ansible.builtin.iptables: |
| 153 | + action: insert |
| 154 | + comment: "Allow DNS query" |
| 155 | + table: filter |
| 156 | + chain: INPUT |
| 157 | + jump: ACCEPT |
| 158 | + protocol: "udp" |
| 159 | + destination_port: 53 |
| 160 | + |
| 161 | + - name: Restart FreeIPA server |
| 162 | + become: true |
| 163 | + ansible.builtin.service: |
| 164 | + name: ipa |
| 165 | + state: restarted |
0 commit comments