|
| 1 | +--- |
| 2 | +- name: Prepare Foreman Setup |
| 3 | + hosts: foreman.localdomain |
| 4 | + become: true |
| 5 | + gather_facts: true |
| 6 | + tasks: |
| 7 | + - name: Ensure hostname is set |
| 8 | + ansible.builtin.hostname: |
| 9 | + name: foreman |
| 10 | + use: systemd |
| 11 | + |
| 12 | + - name: Ensure host entries |
| 13 | + ansible.builtin.blockinfile: |
| 14 | + path: /etc/hosts |
| 15 | + append_newline: true |
| 16 | + prepend_newline: true |
| 17 | + block: | |
| 18 | + 10.0.0.1 host.localdomain host |
| 19 | + 10.0.0.2 foreman.localdomain foreman |
| 20 | + 10.0.0.3 monitoring.localdomain monitoring |
| 21 | +
|
| 22 | + - name: Install epel-release |
| 23 | + ansible.builtin.dnf: |
| 24 | + name: epel-release |
| 25 | + state: installed |
| 26 | + |
| 27 | + - name: Disable repository {{ item }} |
| 28 | + ansible.builtin.ini_file: |
| 29 | + path: "/etc/yum.repos.d/{{ item }}.repo" |
| 30 | + section: "{{ item }}" |
| 31 | + option: enabled |
| 32 | + value: 0 |
| 33 | + loop: |
| 34 | + - epel |
| 35 | + - epel-next |
| 36 | + - epel-cisco-openh264 |
| 37 | + |
| 38 | + - name: Install OpenLDAP server |
| 39 | + ansible.builtin.dnf: |
| 40 | + name: |
| 41 | + - openldap-servers |
| 42 | + - openldap-clients |
| 43 | + - python3-ldap |
| 44 | + state: installed |
| 45 | + enablerepo: epel |
| 46 | + |
| 47 | + - name: Start OpenLDAP server |
| 48 | + ansible.builtin.service: |
| 49 | + name: slapd |
| 50 | + state: started |
| 51 | + enabled: true |
| 52 | + |
| 53 | + - name: OpenLDAP - Define Suffix |
| 54 | + community.general.ldap_attrs: |
| 55 | + dn: olcDatabase={2}mdb,cn=config |
| 56 | + attributes: |
| 57 | + olcSuffix: dc=localdomain |
| 58 | + state: exact |
| 59 | + |
| 60 | + - name: OpenLDAP - Set up admin |
| 61 | + community.general.ldap_attrs: |
| 62 | + dn: olcDatabase={2}mdb,cn=config |
| 63 | + attributes: |
| 64 | + olcRootDN: "{{ ldap_user }}" |
| 65 | + olcRootPW: "{{ ldap_password_encrypted }}" |
| 66 | + state: exact |
| 67 | + |
| 68 | + - name: OpenLDAP - Check for schema cosine |
| 69 | + ansible.builtin.command: ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config -s one '(cn={*}cosine)' dn |
| 70 | + changed_when: false |
| 71 | + register: schema_cosine_loaded |
| 72 | + |
| 73 | + - name: OpenLDAP - Load schema cosine |
| 74 | + ansible.builtin.command: ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif |
| 75 | + when: not schema_cosine_loaded.stdout |
| 76 | + |
| 77 | + - name: OpenLDAP - Check for schema inetorgperson |
| 78 | + ansible.builtin.command: ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config -s one '(cn={*}inetorgperson)' dn |
| 79 | + changed_when: false |
| 80 | + register: schema_inetorgperson_loaded |
| 81 | + |
| 82 | + - name: OpenLDAP - Load schema inetorgperson |
| 83 | + ansible.builtin.command: ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif |
| 84 | + when: not schema_inetorgperson_loaded.stdout |
| 85 | + |
| 86 | + - name: OpenLDAP - Check for schema nis |
| 87 | + ansible.builtin.command: ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config -s one '(cn={*}nis)' dn |
| 88 | + changed_when: false |
| 89 | + register: schema_nis_loaded |
| 90 | + |
| 91 | + - name: OpenLDAP - Load schema nis |
| 92 | + ansible.builtin.command: ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif |
| 93 | + when: not schema_nis_loaded.stdout |
| 94 | + |
| 95 | + - name: OpenLDAP - Root |
| 96 | + community.general.ldap_entry: |
| 97 | + dn: dc=localdomain |
| 98 | + bind_dn: "{{ ldap_user }}" |
| 99 | + bind_pw: "{{ ldap_password }}" |
| 100 | + objectClass: |
| 101 | + - dcObject |
| 102 | + - organizationalUnit |
| 103 | + attributes: |
| 104 | + ou: localdomain |
| 105 | + |
| 106 | + - name: OpenLDAP - OU for User |
| 107 | + community.general.ldap_entry: |
| 108 | + bind_dn: "{{ ldap_user }}" |
| 109 | + bind_pw: "{{ ldap_password }}" |
| 110 | + dn: ou=users,dc=localdomain |
| 111 | + objectClass: organizationalUnit |
| 112 | + |
| 113 | + - name: OpenLDAP - User administrator |
| 114 | + community.general.ldap_entry: |
| 115 | + bind_dn: "{{ ldap_user }}" |
| 116 | + bind_pw: "{{ ldap_password }}" |
| 117 | + dn: cn=administrator,ou=users,dc=localdomain |
| 118 | + objectClass: inetOrgPerson |
| 119 | + attributes: |
| 120 | + sn: User |
| 121 | + description: Administrator |
| 122 | + userPassword: "{{ ldap_password_encrypted }}" |
| 123 | + givenName: Administrator |
| 124 | + mail: administrator@localdomain |
| 125 | + uid: administrator |
| 126 | + |
| 127 | + - name: OpenLDAP - User viewer |
| 128 | + community.general.ldap_entry: |
| 129 | + bind_dn: "{{ ldap_user }}" |
| 130 | + bind_pw: "{{ ldap_password }}" |
| 131 | + dn: cn=viewer,ou=users,dc=localdomain |
| 132 | + objectClass: inetOrgPerson |
| 133 | + attributes: |
| 134 | + sn: User |
| 135 | + description: Viewer |
| 136 | + userPassword: "{{ ldap_password_encrypted }}" |
| 137 | + givenName: Viewer |
| 138 | + mail: viewer@localdomain |
| 139 | + uid: viewer |
| 140 | + |
| 141 | + - name: OpenLDAP - User selfservice |
| 142 | + community.general.ldap_entry: |
| 143 | + bind_dn: "{{ ldap_user }}" |
| 144 | + bind_pw: "{{ ldap_password }}" |
| 145 | + dn: cn=selfservice,ou=users,dc=localdomain |
| 146 | + objectClass: inetOrgPerson |
| 147 | + attributes: |
| 148 | + sn: User |
| 149 | + description: Selfservice |
| 150 | + userPassword: "{{ ldap_password_encrypted }}" |
| 151 | + givenName: Selfservice |
| 152 | + mail: selfservice@localdomain |
| 153 | + uid: selfservice |
| 154 | + |
| 155 | + - name: OpenLDAP - OU for Groups |
| 156 | + community.general.ldap_entry: |
| 157 | + bind_dn: "{{ ldap_user }}" |
| 158 | + bind_pw: "{{ ldap_password }}" |
| 159 | + dn: ou=groups,dc=localdomain |
| 160 | + objectClass: organizationalUnit |
| 161 | + |
| 162 | + - name: OpenLDAP - Group admins |
| 163 | + community.general.ldap_entry: |
| 164 | + bind_dn: "{{ ldap_user }}" |
| 165 | + bind_pw: "{{ ldap_password }}" |
| 166 | + dn: cn=admins,ou=groups,dc=localdomain |
| 167 | + objectClass: posixGroup |
| 168 | + attributes: |
| 169 | + description: Admins |
| 170 | + gidNumber: 666 |
| 171 | + memberUid: administrator |
| 172 | + |
| 173 | + - name: Stop firewalld |
| 174 | + ansible.builtin.service: |
| 175 | + name: firewalld |
| 176 | + state: stopped |
| 177 | + enabled: false |
0 commit comments