Use FQCN builtins

new_release
Emilien Mantel 2021-08-31 13:02:57 +02:00
parent 57aee1fbc4
commit a6e75032a5
11 changed files with 80 additions and 63 deletions

View File

@ -1,8 +1,8 @@
--- ---
# TODO: enable later # TODO: enable later
# enable_list: enable_list:
# - fqcn-builtins - fqcn-builtins
skip_list: skip_list:
- role-name - role-name

View File

@ -33,7 +33,6 @@ before_install:
install: install:
- sudo pip install "ansible-core$ANSIBLE_VERSION" - sudo pip install "ansible-core$ANSIBLE_VERSION"
- sudo pip install ansible-lint - sudo pip install ansible-lint
- ansible-galaxy collection install ansible.posix community.general
script: script:
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM - VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM

View File

@ -1,14 +1,14 @@
--- ---
- name: restart php-fpm - name: restart php-fpm
service: ansible.builtin.service:
name: '{{ php_fpm_service }}' name: '{{ php_fpm_service }}'
state: restarted state: restarted
when: php_install_fpm when: php_install_fpm
notify: docker restart php-fpm notify: docker restart php-fpm
- name: docker restart php-fpm - name: docker restart php-fpm
command: 'service {{ php_fpm_service }} restart' ansible.builtin.command: 'service {{ php_fpm_service }} restart'
args: args:
warn: false warn: false
when: ansible_virtualization_type == 'docker' when: ansible_virtualization_type == 'docker'

View File

@ -1,19 +1,19 @@
--- ---
- name: APT | Install PHP-FPM for Debian based systems - name: APT | Install PHP-FPM for Debian based systems
apt: ansible.builtin.apt:
pkg: "{{ php_fpm_service }}" pkg: "{{ php_fpm_service }}"
state: "{{ 'present' if php_install_fpm else 'absent' }}" state: "{{ 'present' if php_install_fpm else 'absent' }}"
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
- name: SERVICE | Enable service on FreeBSD - name: SERVICE | Enable service on FreeBSD
service: ansible.builtin.service:
name: "{{ php_fpm_service }}" name: "{{ php_fpm_service }}"
enabled: "{{ 'yes' if php_install_fpm else 'no' }}" enabled: "{{ 'true' if php_install_fpm else 'false' }}"
when: ansible_os_family == 'FreeBSD' when: ansible_os_family == 'FreeBSD'
- name: LINEINFILE | PHP configuration - name: LINEINFILE | PHP configuration
lineinfile: ansible.builtin.lineinfile:
dest: '{{ php_fpm_ini }}' dest: '{{ php_fpm_ini }}'
regexp: '^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line: '{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
@ -25,7 +25,7 @@
notify: restart php-fpm notify: restart php-fpm
- name: TEMPLATE | Deploy pool configuration - name: TEMPLATE | Deploy pool configuration
template: ansible.builtin.template:
src: etc/__php__/fpm/pool.d/pool.conf.j2 src: etc/__php__/fpm/pool.d/pool.conf.j2
dest: '{{ php_fpm_pool_dir }}/{{ item.name }}.conf' dest: '{{ php_fpm_pool_dir }}/{{ item.name }}.conf'
owner: root owner: root
@ -35,7 +35,7 @@
notify: restart php-fpm notify: restart php-fpm
- name: FILE | Delete default pool if necessary - name: FILE | Delete default pool if necessary
file: ansible.builtin.file:
path: "{{ php_fpm_pool_dir }}/www.conf" path: "{{ php_fpm_pool_dir }}/www.conf"
state: absent state: absent
when: '"www" not in (ansible_local.hanxhx_php.fpm_pool | map(attribute="name") | list) and php_autoremove_default_pool' when: '"www" not in (ansible_local.hanxhx_php.fpm_pool | map(attribute="name") | list) and php_autoremove_default_pool'

View File

@ -1,17 +1,17 @@
--- ---
- name: INCLUDE_VARS | Related to OS family - name: INCLUDE_VARS | Related to OS family
include_vars: "OS_Family_{{ ansible_os_family }}.yml" ansible.builtin.include_vars: "OS_Family_{{ ansible_os_family }}.yml"
- name: INCLUDE_VARS | Related to OS version - name: INCLUDE_VARS | Related to OS version
include_vars: "{{ item }}" ansible.builtin.include_vars: "{{ item }}"
with_first_found: with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" - "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml" - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- name: SET_FACT | Transform data - name: SET_FACT | Transform data
set_fact: ansible.builtin.set_fact:
__php_fpm_full_pool: | __php_fpm_full_pool: |
[ [
{% for p in php_fpm_poold %} {% for p in php_fpm_poold %}
@ -32,17 +32,20 @@
] ]
- name: SET_FACT | To YAML - name: SET_FACT | To YAML
set_fact: ansible.builtin.set_fact:
php_fpm_full_pool: "{{ __php_fpm_full_pool | from_yaml }}" php_fpm_full_pool: "{{ __php_fpm_full_pool | from_yaml }}"
- name: FILE | Creates ansible facts.d - name: FILE | Creates ansible facts.d
file: ansible.builtin.file:
path: /etc/ansible/facts.d path: /etc/ansible/facts.d
state: directory state: directory
owner: root
group: root
mode: 0755
recurse: true recurse: true
- name: COPY | Manage facts - name: COPY | Manage facts
copy: ansible.builtin.copy:
content: "{ \"fpm_pool\": {{ php_fpm_full_pool | to_nice_json }} }" content: "{ \"fpm_pool\": {{ php_fpm_full_pool | to_nice_json }} }"
dest: /etc/ansible/facts.d/hanxhx_php.fact dest: /etc/ansible/facts.d/hanxhx_php.fact
owner: root owner: root
@ -51,13 +54,13 @@
register: f register: f
- name: SETUP | Gathers new facts - name: SETUP | Gathers new facts
setup: ansible.builtin.setup:
when: f.changed when: f.changed
tags: tags:
- skip_ansible_lint - skip_ansible_lint
- name: APT | Install PHP packages - name: APT | Install PHP packages
apt: ansible.builtin.apt:
pkg: "{{ pkgs }}" pkg: "{{ pkgs }}"
state: present state: present
update_cache: true update_cache: true
@ -68,29 +71,29 @@
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
- name: PKGNG | Install PHP packages - name: PKGNG | Install PHP packages
pkgng: ansible.builtin.pkgng:
name: "{{ php_packages + php_extra_packages | flatten | join(',') }}" name: "{{ php_packages + php_extra_packages | flatten | join(',') }}"
notify: restart php-fpm notify: restart php-fpm
when: ansible_os_family == 'FreeBSD' when: ansible_os_family == 'FreeBSD'
- name: IMPORT_TASKS | PHP-FPM - name: IMPORT_TASKS | PHP-FPM
import_tasks: fpm.yml ansible.builtin.import_tasks: fpm.yml
- name: LINEINFILE | PHP CLI configuration - name: LINEINFILE | PHP CLI configuration
lineinfile: ansible.builtin.lineinfile:
dest: '{{ php_cli_ini }}' dest: '{{ php_cli_ini }}'
regexp: '^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line: '{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
loop: "{{ php_ini | combine(php_ini_cli) | dict2items }}" loop: "{{ php_ini | combine(php_ini_cli) | dict2items }}"
- name: IMPORT_TASKS | Xdebug - name: IMPORT_TASKS | Xdebug
import_tasks: xdebug.yml ansible.builtin.import_tasks: xdebug.yml
- name: APT | Install and configure opcache - name: APT | Install and configure opcache
import_tasks: opcache.yml ansible.builtin.import_tasks: opcache.yml
- name: SERVICE | Ensure PHP-FPM is started - name: SERVICE | Ensure PHP-FPM is started
service: ansible.builtin.service:
name: '{{ php_fpm_service }}' name: '{{ php_fpm_service }}'
state: started state: started
when: php_install_fpm and ansible_virtualization_type != 'docker' when: php_install_fpm and ansible_virtualization_type != 'docker'
@ -98,7 +101,7 @@
- block: - block:
- name: COMMAND | Check if PHP-FPM is started (Docker) - name: COMMAND | Check if PHP-FPM is started (Docker)
command: 'service {{ php_fpm_service }} status' ansible.builtin.command: 'service {{ php_fpm_service }} status'
args: args:
warn: false warn: false
register: dps register: dps
@ -106,7 +109,7 @@
failed_when: false failed_when: false
- name: COMMAND | Ensure PHP-FPM is started (Docker) - name: COMMAND | Ensure PHP-FPM is started (Docker)
command: 'service {{ php_fpm_service }} start' ansible.builtin.command: 'service {{ php_fpm_service }} start'
args: args:
warn: false warn: false
when: dps.stdout.find('is not running') != -1 when: dps.stdout.find('is not running') != -1

View File

@ -3,11 +3,11 @@
- block: - block:
- name: APT | Install APCu - name: APT | Install APCu
apt: ansible.builtin.apt:
pkg: "php-apcu" pkg: "php-apcu"
- name: APT | Install Opcache - name: APT | Install Opcache
apt: ansible.builtin.apt:
pkg: "{{ php_package_prefix }}opcache" pkg: "{{ php_package_prefix }}opcache"
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
@ -15,17 +15,17 @@
- block: - block:
- name: PKGNG | Install APCu - name: PKGNG | Install APCu
pkgng: ansible.builtin.pkgng:
name: "php{{ php_version | replace('.', '') }}-pecl-APCu" name: "php{{ php_version | replace('.', '') }}-pecl-APCu"
- name: PKGNG | Install Opcache - name: PKGNG | Install Opcache
pkgng: ansible.builtin.pkgng:
name: "{{ php_package_prefix }}opcache" name: "{{ php_package_prefix }}opcache"
when: ansible_os_family == 'FreeBSD' when: ansible_os_family == 'FreeBSD'
- name: TEMPLATE | Configure Opcache - name: TEMPLATE | Configure Opcache
template: ansible.builtin.template:
src: "etc/__php__/mods-available/opcache.ini.j2" src: "etc/__php__/mods-available/opcache.ini.j2"
dest: "{{ php_mods_dir }}/opcache.ini" dest: "{{ php_mods_dir }}/opcache.ini"
owner: root owner: root
@ -34,7 +34,7 @@
notify: restart php-fpm notify: restart php-fpm
- name: TEMPLATE | Configure APCu - name: TEMPLATE | Configure APCu
template: ansible.builtin.template:
src: "etc/__php__/mods-available/apcu.ini.j2" src: "etc/__php__/mods-available/apcu.ini.j2"
dest: "{{ php_mods_dir }}/apcu.ini" dest: "{{ php_mods_dir }}/apcu.ini"
owner: root owner: root

View File

@ -3,7 +3,7 @@
- block: - block:
- name: APT | Install xdebug - name: APT | Install xdebug
apt: ansible.builtin.apt:
pkg: "{{ php_xdebug_package }}" pkg: "{{ php_xdebug_package }}"
state: present state: present
update_cache: true update_cache: true
@ -11,12 +11,12 @@
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
- name: PKGNG | Install xdebug - name: PKGNG | Install xdebug
pkgng: ansible.builtin.pkgng:
name: "{{ php_xdebug_package }}" name: "{{ php_xdebug_package }}"
when: ansible_os_family == 'FreeBSD' and php_xdebug_package is defined when: ansible_os_family == 'FreeBSD' and php_xdebug_package is defined
- name: TEMPLATE | Deploy module configurations - name: TEMPLATE | Deploy module configurations
template: ansible.builtin.template:
src: "etc/__php__/mods-available/xdebug.ini.j2" src: "etc/__php__/mods-available/xdebug.ini.j2"
dest: "{{ php_mods_dir }}/xdebug.ini" dest: "{{ php_mods_dir }}/xdebug.ini"
owner: root owner: root
@ -28,13 +28,13 @@
- block: - block:
- name: APT | Uninstall xdebug - name: APT | Uninstall xdebug
apt: ansible.builtin.apt:
pkg: "{{ php_xdebug_package }}" pkg: "{{ php_xdebug_package }}"
state: absent state: absent
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
- name: PKGNG | Uninstall xdebug - name: PKGNG | Uninstall xdebug
pkgng: ansible.builtin.pkgng:
name: "{{ php_xdebug_package }}" name: "{{ php_xdebug_package }}"
state: absent state: absent
when: ansible_os_family == 'FreeBSD' when: ansible_os_family == 'FreeBSD'

View File

@ -1,9 +1,9 @@
--- ---
- name: APT | Install Sury key - name: APT | Install Sury key
apt_key: ansible.builtin.apt_key:
url: 'https://packages.sury.org/php/apt.gpg' url: 'https://packages.sury.org/php/apt.gpg'
- name: APT_REPOSITORY | Add Sury repository - name: APT_REPOSITORY | Add Sury repository
apt_repository: ansible.builtin.apt_repository:
repo: 'deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main' repo: 'deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main'

View File

@ -1,11 +1,11 @@
--- ---
- name: SET_FACT | Prepare test vars - name: SET_FACT | Prepare test vars
set_fact: ansible.builtin.set_fact:
__nginx_conf: /etc/nginx/nginx.conf __nginx_conf: /etc/nginx/nginx.conf
- name: APT | Install packages - name: APT | Install packages
apt: ansible.builtin.apt:
pkg: "{{ p }}" pkg: "{{ p }}"
update_cache: true update_cache: true
cache_valid_time: 3600 cache_valid_time: 3600
@ -20,5 +20,5 @@
- vim - vim
- name: INCLUDE_TASKS | Sury - name: INCLUDE_TASKS | Sury
include_tasks: Debian/sury.yml ansible.builtin.include_tasks: Debian/sury.yml
when: php_version != php_default_version when: php_version != php_default_version

View File

@ -1,10 +1,10 @@
--- ---
- name: SET_FACT | Prepare test vars - name: SET_FACT | Prepare test vars
set_fact: ansible.builtin.set_fact:
__nginx_conf: /usr/local/etc/nginx/nginx.conf __nginx_conf: /usr/local/etc/nginx/nginx.conf
php_xdebug_package: 'php72-pecl-xdebug-2.6.1' php_xdebug_package: 'php72-pecl-xdebug-2.6.1'
- name: PKGNG | Install packages - name: PKGNG | Install packages
pkgng: ansible.builtin.pkgng:
name: ['curl', 'nginx'] name: ['curl', 'nginx']

View File

@ -32,10 +32,10 @@
pre_tasks: pre_tasks:
- name: INCLUDE_TASKS | Pre tasks related to OS - name: INCLUDE_TASKS | Pre tasks related to OS
include_tasks: "includes/pre_{{ ansible_os_family }}.yml" ansible.builtin.include_tasks: "includes/pre_{{ ansible_os_family }}.yml"
- name: USER | Create PHP user - name: USER | Create PHP user
user: ansible.builtin.user:
name: 'foo' name: 'foo'
system: true system: true
create_home: false create_home: false
@ -44,26 +44,29 @@
tasks: tasks:
- name: TEMPLATE | Nginx site config - name: TEMPLATE | Nginx site config
template: ansible.builtin.template:
src: "templates/nginx.conf.j2" src: "templates/nginx.conf.j2"
dest: "{{ __nginx_conf }}" dest: "{{ __nginx_conf }}"
mode: 0644
owner: root
group: root
notify: reload nginx notify: reload nginx
- name: COMMAND | Fix nginx config - name: COMMAND | Fix nginx config
command: "cp {{ __nginx_conf | dirname }}/fastcgi_params {{ __nginx_conf | dirname }}/fastcgi.conf" ansible.builtin.command: "cp {{ __nginx_conf | dirname }}/fastcgi_params {{ __nginx_conf | dirname }}/fastcgi.conf"
args: args:
creates: "{{ __nginx_conf | dirname }}/fastcgi.conf" creates: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx notify: reload nginx
- name: LINEINFILE | Fix nginx config (second step) - name: LINEINFILE | Fix nginx config (second step)
lineinfile: ansible.builtin.lineinfile:
regexp: '^fastcgi_param\s+SCRIPT_FILENAME' regexp: '^fastcgi_param\s+SCRIPT_FILENAME'
line: "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;" line: "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;"
dest: "{{ __nginx_conf | dirname }}/fastcgi.conf" dest: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx notify: reload nginx
- name: SERVICE | Ensure nginx is started - name: SERVICE | Ensure nginx is started
service: ansible.builtin.service:
name: nginx name: nginx
state: started state: started
when: ansible_virtualization_type != 'docker' when: ansible_virtualization_type != 'docker'
@ -71,7 +74,7 @@
- block: - block:
- name: COMMAND | Docker nginx status - name: COMMAND | Docker nginx status
command: service nginx status ansible.builtin.command: service nginx status
args: args:
warn: false warn: false
changed_when: false changed_when: false
@ -79,7 +82,7 @@
register: ngs register: ngs
- name: COMMAND | Docker start nginx - name: COMMAND | Docker start nginx
command: service nginx start ansible.builtin.command: service nginx start
args: args:
warn: false warn: false
when: ngs.stdout.find('nginx is not running') != -1 when: ngs.stdout.find('nginx is not running') != -1
@ -89,13 +92,13 @@
handlers: handlers:
- name: reload nginx - name: reload nginx
service: ansible.builtin.service:
name: nginx name: nginx
state: reloaded state: reloaded
notify: docker reload nginx notify: docker reload nginx
- name: docker reload nginx - name: docker reload nginx
command: service nginx reload ansible.builtin.command: service nginx reload
args: args:
warn: false warn: false
notify: docker reload nginx notify: docker reload nginx
@ -107,36 +110,48 @@
post_tasks: post_tasks:
- name: SHELL | Test php-cli - name: SHELL | Test php-cli
shell: php -i | grep '^PHP Version => {{ php_version }}' | head -n 1 ansible.builtin.shell: set -o pipefail && php -i | grep '^PHP Version => {{ php_version }}' | head -n 1
changed_when: false changed_when: false
register: p register: p
failed_when: p.stdout == '' failed_when: p.stdout == ''
args:
executable: /bin/bash
- name: FILE | Create /var/www - name: FILE | Create /var/www
file: ansible.builtin.file:
dest: /var/www dest: /var/www
state: directory state: directory
owner: root
group: root
mode: 0755
- name: COPY | Add phpinfo - name: COPY | Add phpinfo
copy: ansible.builtin.copy:
dest: /var/www/phpinfo.php dest: /var/www/phpinfo.php
content: '<?php phpinfo();' content: '<?php phpinfo();'
owner: root
group: root
mode: 0644
- name: COPY | Add ini test file - name: COPY | Add ini test file
copy: ansible.builtin.copy:
dest: /var/www/ini.php dest: /var/www/ini.php
content: '<?php echo ini_get("memory_limit") . "\n";' content: '<?php echo ini_get("memory_limit") . "\n";'
owner: root
group: root
mode: 0644
- name: SHELL | Check vhost - name: SHELL | Check vhost
shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version {{ php_version }}' | sed -r 's/<//g'" ansible.builtin.shell: "set -o pipefail && curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version {{ php_version }}' | sed -r 's/<//g'"
args: args:
warn: false warn: false
executable: /bin/bash
changed_when: false changed_when: false
register: c register: c
failed_when: c.stdout == '' failed_when: c.stdout == ''
- name: SHELL | Check custom php value - name: SHELL | Check custom php value
shell: "curl -H 'Host: {{ vhost }}' http://127.0.0.1/ini.php 2> /dev/null" ansible.builtin.shell: "curl -H 'Host: {{ vhost }}' http://127.0.0.1/ini.php 2> /dev/null"
args: args:
warn: false warn: false
changed_when: false changed_when: false
@ -144,11 +159,11 @@
failed_when: 'php_fpm_poold.1.php_admin_value.memory_limit not in c.stdout' failed_when: 'php_fpm_poold.1.php_admin_value.memory_limit not in c.stdout'
- name: URI | Check ping - name: URI | Check ping
uri: ansible.builtin.uri:
url: "http://localhost{{ php_fpm_poold.0.ping_path }}" url: "http://localhost{{ php_fpm_poold.0.ping_path }}"
when: php_fpm_poold.0.ping_path is defined when: php_fpm_poold.0.ping_path is defined
- name: URI | Check status - name: URI | Check status
uri: ansible.builtin.uri:
url: "http://localhost{{ php_fpm_poold.0.status_path }}" url: "http://localhost{{ php_fpm_poold.0.status_path }}"
when: php_fpm_poold.0.status_path is defined when: php_fpm_poold.0.status_path is defined