Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.5 KiB

style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
style and variables refactoring - Coherent quotation style Single quotes for text variable (even if implicit), no quotes for variable and conditional statements, if not required. - Some useful tags added: * ssh_certs renewal of server SSH certificates and configuration of authorized CA. * tls_pub renewal of public TLS certificates (let's encrypt) and certbot configuration. * tls_int renewal of internal TLS certificates (service authorizations) and configuration of authorized internal CA. *(ToDo: deployment of Certificate Revokation Lists)* * lxc deployment of new containers (deployment of configuration file excluded, for instance change in ip address are always applied and trigger a container restart even if you skip this tag. * packages installation and upgrade of software packages (apt, opkg or tarballs) * service_password create new random password for services-only password, for routine rotation. Not meant to be skipped (some roles need to know the service password, so they do a rotation). - prepare_host - ssh_server - lxc_guest - ldap - gitlab - x509_subject_prefix - x509_ldap_suffix *Replaces:* x509_suffix in ldap.yaml - letsencrypt_email Used in roles/certbot and roles/gitlab - root_ca_cert *Replaces:* ssl_ca_cert and files/lilik_x1.crt New defaults: - ldap_domain | default: `${domain}` - server_fqdn | default: `${hostname}.dmz.${domain}` *Replaces:* fqdn_domain Removed: - fqdn_dmain - x509_suffix *Replaced by:* x509_ldap_suffix in common New defaults: - server_fqdn | default: `${hostname}.${domain}` *Replaces*: fqdn - ldap_domain | default: `${domain}` - ldap_server | default: `ldap1.dmz.${domain}` - ldap_basedn | default: `dn(${ldap_domain})` - enable_https | default: `true` New defaults: - server_fqdn | default: `${hostname}.${domain}`
5 years ago
  1. ---
  2. - name: 'check if container dir exists'
  3. stat:
  4. path: '/var/lib/lxc/{{ vm_name }}'
  5. register: container_dir
  6. tags:
  7. - 'lxc'
  8. - name: 'check if container exists'
  9. container_exists:
  10. name: '{{ vm_name }}'
  11. register: container_exists
  12. tags:
  13. - 'lxc'
  14. - name: 'check if release is supported'
  15. assert:
  16. that: distro in [ 'bullseye', 'sid', 'buster' ]
  17. msg: 'release {{ distro }} not supported by debian template'
  18. tags:
  19. - 'lxc'
  20. - block:
  21. - name: 'privileged | create lxc container'
  22. lxc_container:
  23. name: '{{ vm_name }}'
  24. backing_store: 'lvm'
  25. fs_size: '{{ vm_size }}'
  26. vg_name: '{{ vg_name }}'
  27. lv_name: 'vm_{{ vm_name }}'
  28. fs_type: 'xfs'
  29. container_log: true
  30. template: 'debian'
  31. template_options: '--release {{ distro }} --packages=ssh,python3,python3-apt'
  32. state: 'stopped'
  33. # suppress messages related to file descriptors
  34. # leaking when lvm is invoked
  35. environment:
  36. LVM_SUPPRESS_FD_WARNINGS: 1
  37. when: not unprivileged
  38. - name: 'unprivileged | upload bash script'
  39. copy:
  40. src: 'find_subxid.sh'
  41. dest: 'find_subxid.sh'
  42. when: unprivileged
  43. - name: 'unprivileged | get free subxid mappings'
  44. command: 'bash find_subxid.sh'
  45. register: avail_subxid
  46. when: unprivileged
  47. - name: 'unprivileged | set subxid mappings'
  48. set_fact:
  49. subuidmap: '{{ avail_subxid.stdout_lines[0] }}'
  50. subgidmap: '{{ avail_subxid.stdout_lines[1] }}'
  51. when: unprivileged
  52. - name: 'unprivileged | create system subxid mappings'
  53. command: >-
  54. usermod
  55. -v {{ '{}-{}'.format(subuidmap.split(' ')[0],
  56. subuidmap.split(' ')[0]|int+subuidmap.split(' ')[1]|int-1) }}
  57. -w {{ '{}-{}'.format(subgidmap.split(' ')[0],
  58. subgidmap.split(' ')[0]|int+subgidmap.split(' ')[1]|int-1) }}
  59. root
  60. - name: 'unprivileged | create config seed'
  61. copy:
  62. content: |
  63. lxc.idmap = u 0 {{ subuidmap }}
  64. lxc.idmap = g 0 {{ subgidmap }}
  65. dest: '/tmp/lxc_unpriv_config'
  66. when: unprivileged
  67. - name: 'unprivileged | create lxc container'
  68. lxc_container:
  69. name: '{{ vm_name }}'
  70. backing_store: 'lvm'
  71. fs_type: 'xfs'
  72. fs_size: '{{ vm_size }}'
  73. vg_name: '{{ vg_name }}'
  74. lv_name: 'vm_{{ vm_name }}'
  75. container_log: true
  76. template: 'download'
  77. template_options: '-d debian -r {{ distro }} -a amd64'
  78. config: '/tmp/lxc_unpriv_config'
  79. state: 'stopped'
  80. when: unprivileged
  81. - name: 'deploy container config'
  82. template:
  83. src: 'config.j2'
  84. dest: '/var/lib/lxc/{{ vm_name }}/config'
  85. - name: 'unprivileged | tweak config'
  86. lxc_container:
  87. name: '{{ vm_name }}'
  88. container_command: |
  89. echo 'nameserver {{ hostvars | ip_from_inventory('vm_gateway') }}' > /etc/resolv.conf
  90. apt update
  91. apt install -y python3 python3-apt
  92. systemctl mask systemd-journald-audit.socket
  93. state: 'stopped'
  94. - name: 'start container'
  95. lxc_container:
  96. name: '{{ vm_name }}'
  97. state: 'started'
  98. when: auto_start|bool
  99. when: not (container_exists.exists and container_dir.stat.isdir)
  100. tags:
  101. - 'lxc'
  102. - name: 'read unprivileged status from config'
  103. command: >-
  104. grep -e '^lxc.idmap = ' /var/lib/lxc/{{ vm_name }}/config
  105. register: unpriv_status
  106. changed_when: false
  107. failed_when: unpriv_status.rc > 1
  108. - name: 'set unprivileged status from config'
  109. set_fact:
  110. unprivileged: true
  111. subuidmap: '{{ unpriv_status.stdout_lines[0] | replace("lxc.idmap = u 0 ", "") }}'
  112. subgidmap: '{{ unpriv_status.stdout_lines[1] | replace("lxc.idmap = g 0 ", "") }}'
  113. when: unpriv_status.rc == 0
  114. - name: 'update container config'
  115. template:
  116. src: 'config.j2'
  117. dest: '/var/lib/lxc/{{ vm_name }}/config'
  118. register: container_config
  119. notify: 'restart container'
  120. - name: 'set container running state'
  121. lxc_container:
  122. name: '{{ vm_name }}'
  123. state: '{{ container_state }}'
  124. register: container_running_state
  125. tags:
  126. - 'lxc'
  127. - name: 'update container resolv.conf'
  128. template:
  129. src: 'resolv.conf.j2'
  130. dest: '/etc/resolv.conf'
  131. delegate_to: '{{ vm_name }}'
  132. connection: 'ssh_lxc'
  133. - name: 'update container net config'
  134. copy:
  135. src: 'interfaces'
  136. dest: '/etc/network/interfaces'
  137. delegate_to: '{{ vm_name }}'
  138. connection: 'ssh_lxc'
  139. notify: 'restart container'
  140. - name: 'update container apt config'
  141. lineinfile:
  142. path: '/etc/apt/apt.conf.d/02periodic'
  143. line: '{{ item.key }} "{{ item.value }}";'
  144. regexp: '^{{ item.key }} '
  145. create: true
  146. loop:
  147. - { key: 'APT::Periodic::Enable', value: '1' }
  148. - { key: 'APT::Periodic::Update-Package-Lists', value: '1' }
  149. - { key: 'APT::Periodic::Verbose', value: '2' }
  150. delegate_to: '{{ vm_name }}'
  151. connection: 'ssh_lxc'
  152. - meta: 'flush_handlers'
  153. - name: 'MONITORING | add to monitored hosts'
  154. block:
  155. - name: 'MONITORING | add to monitored hosts'
  156. set_fact:
  157. monitoring_entry: >
  158. {{ { 'address': ansible_host,
  159. 'host_type': 'lxc_vm' } }}
  160. - name: 'MONITORING | update monitoring facts'
  161. set_fact:
  162. monitoring_facts: >
  163. {{ hostvars[monitoring_host]['monitoring_facts']
  164. | default({})
  165. | combine({host_fqdn: monitoring_entry}) }}
  166. delegate_facts: true
  167. delegate_to: '{{ monitoring_host }}'
  168. tags:
  169. - 'monitoring'
  170. ...