|  | 
|  | 1 | +--- | 
|  | 2 | + | 
|  | 3 | +# Copyright 2023 Cloudera, Inc. All Rights Reserved. | 
|  | 4 | +# | 
|  | 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 6 | +# you may not use this file except in compliance with the License. | 
|  | 7 | +# You may obtain 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, | 
|  | 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | +# See the License for the specific language governing permissions and | 
|  | 15 | +# limitations under the License. | 
|  | 16 | + | 
|  | 17 | +- name: Disable SELinux | 
|  | 18 | +  ansible.builtin.selinux: | 
|  | 19 | +    state: disabled | 
|  | 20 | +  notify: restart host | 
|  | 21 | + | 
|  | 22 | +- name: Set up DNS and networking | 
|  | 23 | +  when: enable_dns | 
|  | 24 | +  block: | 
|  | 25 | +    - name: Update RHEL networking | 
|  | 26 | +      when: ansible_facts['os_family'] == 'RedHat' | 
|  | 27 | +      block: | 
|  | 28 | +        - name: Set cloud-init to preserve hostname (RHEL) | 
|  | 29 | +          ansible.builtin.lineinfile: | 
|  | 30 | +            path: /etc/cloud/cloud.cfg | 
|  | 31 | +            regex: "^(#)?preserve_hostname" | 
|  | 32 | +            line: "preserve_hostname: 1" | 
|  | 33 | +            state: present | 
|  | 34 | +          notify: restart host | 
|  | 35 | + | 
|  | 36 | +        - name: Set interface config to preserve resolv.conf changes (RHEL)' | 
|  | 37 | +          ansible.builtin.lineinfile: | 
|  | 38 | +            path: "/etc/sysconfig/network-scripts/ifcfg-{{ ansible_default_ipv4.interface }}" | 
|  | 39 | +            regex: "^(#)?PEERDNS" | 
|  | 40 | +            line: "PEERDNS=no" | 
|  | 41 | +            state: present | 
|  | 42 | +          notify: restart host | 
|  | 43 | + | 
|  | 44 | +        - name: Set /etc/NetworkManager/conf.d/disable-resolve.conf-managing.conf (RHEL) | 
|  | 45 | +          ansible.builtin.copy: | 
|  | 46 | +            dest: /etc/NetworkManager/conf.d/disable-resolve.conf-managing.conf | 
|  | 47 | +            content: | | 
|  | 48 | +              # Generated by Ansible | 
|  | 49 | +              [main] | 
|  | 50 | +              dns=none | 
|  | 51 | +          notify: restart host | 
|  | 52 | + | 
|  | 53 | +        - name: Set /etc/resolv.conf directly | 
|  | 54 | +          ansible.builtin.copy: | 
|  | 55 | +            dest: /etc/resolv.conf | 
|  | 56 | +            content: | | 
|  | 57 | +              # Generated by Ansible | 
|  | 58 | +              search {{ ipaserver_domain }} | 
|  | 59 | +              {{ ['nameserver '] | product(ipa_server_ips | sort) | map('join') | join('\n') }} | 
|  | 60 | +          notify: restart host | 
|  | 61 | + | 
|  | 62 | +    - name: Set /etc/hostname to the FQDN | 
|  | 63 | +      ansible.builtin.copy: | 
|  | 64 | +        content: "{{ inventory_hostname }}" | 
|  | 65 | +        dest: /etc/hostname | 
|  | 66 | +      notify: restart host | 
|  | 67 | + | 
|  | 68 | +    - name: Set /etc/hosts | 
|  | 69 | +      ansible.builtin.copy: | 
|  | 70 | +        dest: /etc/hosts | 
|  | 71 | +        content: | | 
|  | 72 | +          # Set by Ansible | 
|  | 73 | +          {{ ansible_default_ipv4.address }} {{ inventory_hostname }} {{ inventory_hostname_short }} | 
|  | 74 | +      notify: restart host | 
|  | 75 | + | 
|  | 76 | +    - name: Set /etc/dhcp/dhclient.conf for domain search and name servers | 
|  | 77 | +      ansible.builtin.lineinfile: | 
|  | 78 | +        path: /etc/dhcp/dhclient.conf | 
|  | 79 | +        regex: "^(#)?{{ dhclient_entry.value }}" | 
|  | 80 | +        line: "{{ dhclient_entry.value }}" | 
|  | 81 | +        state: present | 
|  | 82 | +      loop: "{{ entries | dict2items }}" | 
|  | 83 | +      loop_control: | 
|  | 84 | +        loop_var: dhclient_entry | 
|  | 85 | +        label: "{{ dhclient_entry.key }}" | 
|  | 86 | +      vars: | 
|  | 87 | +        entries: | 
|  | 88 | +          domain_search: supersede domain-search "{{ ipaserver_domain }}"; | 
|  | 89 | +          domain_name_servers: supersede domain-name-servers {{ ipa_server_ips | sort | union(fallback_nameservers) | join(', ') }}; | 
|  | 90 | +      notify: restart host | 
|  | 91 | + | 
|  | 92 | +- name: Flush handlers | 
|  | 93 | +  ansible.builtin.meta: flush_handlers | 
|  | 94 | + | 
|  | 95 | +- name: Set up the FreeIPA Client | 
|  | 96 | +  ansible.builtin.include_role: | 
|  | 97 | +    name: freeipa.ansible_freeipa.ipaclient | 
|  | 98 | +  vars: | 
|  | 99 | +    state: present | 
|  | 100 | +    ipaclient_hostname: "{{ inventory_hostname }}" | 
|  | 101 | +    ipaclient_servers: "{{ ipa_hosts }}" | 
|  | 102 | +    ipaserver_setup_dns: "{{ enable_dns }}" | 
|  | 103 | +    ipasssd_enable_dns_updates: "{{ enable_dns }}" | 
|  | 104 | +    ipaclient_mkhomedir: yes | 
0 commit comments