diff --git a/filter_plugins/__pycache__/php.cpython-37.pyc b/filter_plugins/__pycache__/php.cpython-37.pyc new file mode 100644 index 0000000..0a4d8ec Binary files /dev/null and b/filter_plugins/__pycache__/php.cpython-37.pyc differ diff --git a/filter_plugins/php.py b/filter_plugins/php.py new file mode 100644 index 0000000..4955350 --- /dev/null +++ b/filter_plugins/php.py @@ -0,0 +1,10 @@ +def php_socket(php_version, pool_name): + return '/run/php/php%s-%s-fpm.sock' % (php_version, pool_name) + +class FilterModule(object): + ''' PHP module ''' + + def filters(self): + return { + 'php_socket': php_socket, + } diff --git a/filter_plugins/php.pyc b/filter_plugins/php.pyc new file mode 100644 index 0000000..8ebb601 Binary files /dev/null and b/filter_plugins/php.pyc differ diff --git a/tasks/main.yml b/tasks/main.yml index 11187b3..844cc1f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,6 +15,45 @@ - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml" - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" +- name: SET_FACT | Transform data + set_fact: + __php_fpm_full_pool: | + [ + {% for p in php_fpm_poold %} + { + name: "{{ p.name | default(p.pool_name) }}", + listen: "{{ item.listen | default(php_version | php_socket(p.name | default(p.pool_name))) }}", + user: "{{ item.user | default(php_default_user_group) }}", + group: "{{ item.group | default(php_default_user_group) }}", + listen_owner: "{{ item.listen_owner | default(php_default_user_group) }}", + listen_group: "{{ item.listen_owner | default(php_default_user_group) }}", + {% for k, v in p.items() %} + {% if k not in ['name', 'pool_name', 'listen', 'user', 'group', 'listen_owner'] %} + {{ k }}: "{{ v }}"{% if not loop.last %},{% endif %} + {% endif %} + {% endfor %} + }{% if not loop.last %},{% endif %} + {% endfor %} + ] + +- name: SET_FACT | To YAML + set_fact: + php_fpm_full_pool: "{{ __php_fpm_full_pool | from_yaml }}" + +- name: FILE | Creates ansible facts.d + file: + path: /etc/ansible/facts.d + state: directory + recurse: yes + +- name: COPY | Manage current repositories + copy: + content: "{ \"php_fpm_full_pool\": {{ php_fpm_full_pool | to_json }} }" + dest: /etc/ansible/facts.d/php_fpm_pool.fact + +- debug: var=php_fpm_full_pool +- fail: msg='ok' + - name: APT | Install PHP packages apt: pkg: "{{ item }}" diff --git a/tests/test.yml b/tests/test.yml index 35cfc94..78ff0c9 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -25,6 +25,16 @@ display_errors: 'Off' php_admin_flag: memory_limit: '128M' + - pool_name: 'test_ansible2' + pm: 'dynamic' + pm_max_children: 250 + pm_start_servers: 10 + pm_min_spare_servers: 10 + pm_max_spare_servers: 20 + php_flag: + display_errors: 'On' + php_admin_flag: + memory_limit: '64M' pre_tasks: