From 12cebfa71cb10ce66812076ea0320638ef2ae270 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Fri, 11 Oct 2019 21:43:21 +0200 Subject: [PATCH] lxc-php: refactor tasks for better maintainability --- CHANGELOG.md | 9 ++-- lxc-php/tasks/main.yml | 18 ++++--- lxc-php/tasks/misc.yml | 24 +++++++++ lxc-php/tasks/php.yml | 109 ---------------------------------------- lxc-php/tasks/php56.yml | 16 ++++++ lxc-php/tasks/php70.yml | 16 ++++++ lxc-php/tasks/php73.yml | 31 ++++++++++++ 7 files changed, 104 insertions(+), 119 deletions(-) create mode 100644 lxc-php/tasks/misc.yml delete mode 100644 lxc-php/tasks/php.yml create mode 100644 lxc-php/tasks/php56.yml create mode 100644 lxc-php/tasks/php70.yml create mode 100644 lxc-php/tasks/php73.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 904651f6..e8139d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,14 +35,15 @@ The **patch** part changes incrementally at each release. * evolinux-base: use "evolinux_internal_group" for SSH authentication * evomaintenance: Turn on API by default (instead of DB) * evomaintenance: upstream version 0.5.1 -* php: By default, allow 128M for OpCache (instead of 64M) -* squid: Remove wait time when we turn off squid -* squid: split systemd tasks into own file -* varnish: remove custom ExecReload= script for Debian 10+ * lxc: remove useless loop in apt execution * lxc: update our default template to be compatible with Debian 10 * lxc: rely on lxc_container module instead of command module +* lxc-php: refactor tasks for better maintainability +* php: By default, allow 128M for OpCache (instead of 64M) * php: Don't set a chroot for the default fpm pool +* squid: Remove wait time when we turn off squid +* squid: split systemd tasks into own file +* varnish: remove custom ExecReload= script for Debian 10+ ### Fixed * lxc-php: Don't remove the default pool diff --git a/lxc-php/tasks/main.yml b/lxc-php/tasks/main.yml index f17cad4a..7970eb74 100644 --- a/lxc-php/tasks/main.yml +++ b/lxc-php/tasks/main.yml @@ -3,16 +3,22 @@ include_role: name: lxc -- include: "php.yml name={{item.name}}" +- name: Update APT cache + command: "lxc-attach -n {{name}} -- apt-get update" + +- include: "php56.yml" with_items: - "{{ lxc_containers }}" + when: name == "php56" -- name: Ensure containers root directory is 755 - file: - path: "/var/lib/lxc/{{ item.name }}/rootfs" - state: directory - mode: '0755' +- include: "php70.yml" with_items: - "{{ lxc_containers }}" + when: name == "php70" +- include: "php73.yml" + with_items: + - "{{ lxc_containers }}" + when: name == "php73" +- include: "misc.yml" diff --git a/lxc-php/tasks/misc.yml b/lxc-php/tasks/misc.yml new file mode 100644 index 00000000..fb4e5f2a --- /dev/null +++ b/lxc-php/tasks/misc.yml @@ -0,0 +1,24 @@ +--- + +- name: Configure ssmtp + replace: + name: "/var/lib/lxc/{{name}}/rootfs/etc/ssmtp/ssmtp.conf" + regexp: "{{ item.regexp }}" + replace: "{{ item.replace }}" + with_dict: + - { regexp: "^mailhub=.*$", replace: "mailhub=127.0.0.1"} + - { regexp: "^#FromLineOverride=.*$", replace: "FromLineOverride=YES"} + - { regexp: "^hostname=.*", replace: "hostname={{ansible_fqdn}}"} + +- name: Configure timezone + copy: + dest: "/var/lib/lxc/{{name}}/rootfs/etc/timezone" + content: "Europe/Paris\n" + +- name: Ensure containers root directory is 755 + file: + path: "/var/lib/lxc/{{ item.name }}/rootfs" + state: directory + mode: '0755' + with_items: + - "{{ lxc_containers }}" diff --git a/lxc-php/tasks/php.yml b/lxc-php/tasks/php.yml deleted file mode 100644 index 25b72ccd..00000000 --- a/lxc-php/tasks/php.yml +++ /dev/null @@ -1,109 +0,0 @@ -# -# This playbook configures PHP (php-fpm and specific extensions) inside -# container {{name}}. -# - ---- -- name: Update APT cache - command: "lxc-attach -n {{name}} -- apt-get update" - -- name: Install PHP packages - command: "lxc-attach -n {{name}} -- apt-get install -y php5-fpm php5-cli php5-gd php5-imap php5-ldap php5-mcrypt php5-mysql php5-pgsql php-gettext php5-intl php5-curl php5-ssh2 libphp-phpmailer ssmtp git zip unzip" - when: name == 'php56' - -- name: Update APT cache - command: "lxc-attach -n {{name}} -- apt-get update" - when: name == 'php70' - -- name: Install PHP packages - command: "lxc-attach -n {{name}} -- apt-get install -y php-fpm php-cli php-gd php-intl php-imap php-ldap php-mcrypt php-mysql php-pgsql php-gettext php-curl php-ssh2 composer libphp-phpmailer ssmtp git zip unzip php-zip" - when: name == 'php70' - -- name: Update APT cache - command: "lxc-attach -n {{name}} -- apt-get update" - when: name == 'php73' - -- name: Install requirements for sury repository - command: "lxc-attach -n {{name}} -- apt-get install -y --no-install-recommends wget apt-transport-https ca-certificates gnupg" - when: name == 'php73' - -- name: Add sury APT repository - copy: - content: "deb https://packages.sury.org/php/ stretch main" - dest: "/var/lib/lxc/{{name}}/rootfs/etc/apt/sources.list.d/sury.list" - mode: "0644" - when: name == 'php73' - -- name: Add sury GPG key - shell: "wget -O- https://packages.sury.org/php/apt.gpg |lxc-attach -n {{name}} -- apt-key add -" - when: name == 'php73' - -- name: Update APT cache - command: "lxc-attach -n {{name}} -- apt-get update" - when: name == 'php73' - -- name: Install PHP packages - command: "lxc-attach -n {{name}} -- apt-get install -y php7.3 php7.3-fpm php7.3-cli php7.3-curl php7.3-mysql php7.3-pgsql php7.3-ldap php7.3-imap php7.3-gd php-ssh2 php-gettext composer libphp-phpmailer ssmtp git zip unzip php7.3-zip" - when: name == 'php73' - -- name: Copy evolinux PHP 5.6 configuration - template: - src: z-evolinux-defaults.ini.j2 - dest: "{{ line_item }}" - mode: "0644" - notify: "Reload {{name}}-fpm" - when: name == 'php56' - with_items: - - "/var/lib/lxc/{{name}}/rootfs/etc/php5/fpm/conf.d/z-evolinux-defaults.ini" - - "/var/lib/lxc/{{name}}/rootfs/etc/php5/cli/conf.d/z-evolinux-defaults.ini" - loop_control: - loop_var: line_item - -- name: Copy evolinux PHP 7.0 configuration - template: - src: z-evolinux-defaults.ini.j2 - dest: "{{ line_item }}" - mode: "0644" - notify: "Reload {{name}}-fpm" - when: name == 'php70' - with_items: - - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.0/fpm/conf.d/z-evolinux-defaults.ini" - - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.0/cli/conf.d/z-evolinux-defaults.ini" - loop_control: - loop_var: line_item - -- name: Copy evolinux PHP 7.3 configuration - template: - src: z-evolinux-defaults.ini.j2 - dest: "{{ line_item }}" - mode: "0644" - notify: "Reload {{name}}-fpm" - when: name == 'php73' - with_items: - - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.3/fpm/conf.d/z-evolinux-defaults.ini" - - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.3/cli/conf.d/z-evolinux-defaults.ini" - loop_control: - loop_var: line_item - -- name: Configure ssmtp - replace: - name: "/var/lib/lxc/{{name}}/rootfs/etc/ssmtp/ssmtp.conf" - regexp: "^mailhub=.*$" - replace: "mailhub=127.0.0.1" - -- name: Configure ssmtp - replace: - name: "/var/lib/lxc/{{name}}/rootfs/etc/ssmtp/ssmtp.conf" - regexp: "^#FromLineOverride=.*$" - replace: "FromLineOverride=YES" - -- name: Configure ssmtp - replace: - name: "/var/lib/lxc/{{name}}/rootfs/etc/ssmtp/ssmtp.conf" - regexp: "^hostname=.*" - replace: "hostname={{ansible_fqdn}}" - -- name: Configure timezone - copy: - dest: "/var/lib/lxc/{{name}}/rootfs/etc/timezone" - content: "Europe/Paris\n" diff --git a/lxc-php/tasks/php56.yml b/lxc-php/tasks/php56.yml new file mode 100644 index 00000000..ab7595ae --- /dev/null +++ b/lxc-php/tasks/php56.yml @@ -0,0 +1,16 @@ +--- + +- name: Install PHP packages + command: "lxc-attach -n {{name}} -- apt-get install -y php5-fpm php5-cli php5-gd php5-imap php5-ldap php5-mcrypt php5-mysql php5-pgsql php-gettext php5-intl php5-curl php5-ssh2 libphp-phpmailer ssmtp git zip unzip" + +- name: Copy evolinux PHP 5.6 configuration + template: + src: z-evolinux-defaults.ini.j2 + dest: "{{ line_item }}" + mode: "0644" + notify: "Reload {{name}}-fpm" + with_items: + - "/var/lib/lxc/{{name}}/rootfs/etc/php5/fpm/conf.d/z-evolinux-defaults.ini" + - "/var/lib/lxc/{{name}}/rootfs/etc/php5/cli/conf.d/z-evolinux-defaults.ini" + loop_control: + loop_var: line_item diff --git a/lxc-php/tasks/php70.yml b/lxc-php/tasks/php70.yml new file mode 100644 index 00000000..1f5eb181 --- /dev/null +++ b/lxc-php/tasks/php70.yml @@ -0,0 +1,16 @@ +--- + +- name: Install PHP packages + command: "lxc-attach -n {{name}} -- apt-get install -y php-fpm php-cli php-gd php-intl php-imap php-ldap php-mcrypt php-mysql php-pgsql php-gettext php-curl php-ssh2 composer libphp-phpmailer ssmtp git zip unzip php-zip" + +- name: Copy evolinux PHP 7.0 configuration + template: + src: z-evolinux-defaults.ini.j2 + dest: "{{ line_item }}" + mode: "0644" + notify: "Reload {{name}}-fpm" + with_items: + - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.0/fpm/conf.d/z-evolinux-defaults.ini" + - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.0/cli/conf.d/z-evolinux-defaults.ini" + loop_control: + loop_var: line_item diff --git a/lxc-php/tasks/php73.yml b/lxc-php/tasks/php73.yml new file mode 100644 index 00000000..ac0007d8 --- /dev/null +++ b/lxc-php/tasks/php73.yml @@ -0,0 +1,31 @@ +--- + +- name: Install requirements for sury repository + command: "lxc-attach -n {{name}} -- apt-get install -y --no-install-recommends wget apt-transport-https ca-certificates gnupg" + +- name: Add sury APT repository + copy: + content: "deb https://packages.sury.org/php/ stretch main" + dest: "/var/lib/lxc/{{name}}/rootfs/etc/apt/sources.list.d/sury.list" + mode: "0644" + +- name: Add sury GPG key + shell: "wget -O- https://packages.sury.org/php/apt.gpg |lxc-attach -n {{name}} -- apt-key add -" + +- name: Update APT cache + command: "lxc-attach -n {{name}} -- apt-get update" + +- name: Install PHP packages + command: "lxc-attach -n {{name}} -- apt-get install -y php7.3 php7.3-fpm php7.3-cli php7.3-curl php7.3-mysql php7.3-pgsql php7.3-ldap php7.3-imap php7.3-gd php-ssh2 php-gettext composer libphp-phpmailer ssmtp git zip unzip php7.3-zip" + +- name: Copy evolinux PHP 7.3 configuration + template: + src: z-evolinux-defaults.ini.j2 + dest: "{{ line_item }}" + mode: "0644" + notify: "Reload {{name}}-fpm" + with_items: + - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.3/fpm/conf.d/z-evolinux-defaults.ini" + - "/var/lib/lxc/{{name}}/rootfs/etc/php/7.3/cli/conf.d/z-evolinux-defaults.ini" + loop_control: + loop_var: line_item