diff --git a/.kitchen.yml b/.kitchen.yml index d542117..ac02880 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,4 +1,3 @@ ---- driver: name: docker_cli @@ -9,15 +8,16 @@ provisioner: name: ansible_playbook hosts: localhost require_ansible_repo: false - require_ansible_omnibus: false + require_ansible_omnibus: true require_chef_for_busser: true ansible_verbose: false + ansible_version: <% if ENV['ANSIBLE_VERSION'] %><%= ENV['ANSIBLE_VERSION'] %><% else %><%= '2.4.6.0' %><% end %> ansible_inventory: ./test/integration/inventory platforms: - name: debian-9 driver_config: - image: "nishiki/debian9:ansible-<%= ENV['ANSIBLE_VERSION'] ? ENV['ANSIBLE_VERSION'] : '2.7' %>" + image: nishiki/ansible:stretch command: /bin/systemd volume: - /sys/fs/cgroup:/sys/fs/cgroup:ro diff --git a/.rubocop.yml b/.rubocop.yml index 66555b6..ab3522c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,4 @@ ---- + AllCops: Exclude: - db/**/* diff --git a/.travis.yml b/.travis.yml index 1693c6c..7b2f4c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,18 @@ ---- sudo: required language: ruby env: - - ANSIBLE_VERSION=2.5 - - ANSIBLE_VERSION=2.6 - - ANSIBLE_VERSION=2.7 + - ANSIBLE_VERSION=2.4.6.0 + - ANSIBLE_VERSION=2.5.7.0 + - ANSIBLE_VERSION=2.6.2.0 services: - docker before_install: - bundle install - - sudo pip install --upgrade pip - - sudo pip install yamllint - - sudo pip install ansible-lint - - git clone https://github.com/ansible/galaxy-lint-rules.git script: - kitchen conv phpfpm-debian-9 - kitchen conv phpfpm-debian-9 | grep changed=0 - kitchen verify phpfpm-debian-9 - - ansible-lint -r galaxy-lint-rules/rules . - - yamllint . - -notifications: - webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/.yamllint b/.yamllint deleted file mode 100644 index 5465b58..0000000 --- a/.yamllint +++ /dev/null @@ -1,12 +0,0 @@ ---- -extends: default - -ignore: | - .kitchen/* - vendor/ - -rules: - line-length: - max: 120 - level: warning - truthy: false diff --git a/CHANGELOG.md b/CHANGELOG.md index b1bda58..30aede0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,21 +1,4 @@ # CHANGELOG +## v1.0.0 (2018-08-11) -This project adheres to [Semantic Versioning](http://semver.org/). -Which is based on [Keep A Changelog](http://keepachangelog.com/) - -## [Unreleased] - -## v1.2.0 (2018-12-01) -- BREAKING CHANGE: change with_items to loop -- test: add test with ansible 2.7 -- test: add ansible-lint -- test: add yamllint - -## v1.1.0 (2018-09-30) -- feat: set attributes on homes directories -- feat: remove phpfpm_group var -- style: replace include_tasks to import_tasks -- fix: group permission in pools template - -## v1.0.0 (2018-08-15) -- first version +* first version diff --git a/README.md b/README.md index b66a62a..d1c7321 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Ansible role: PHP FPM -[](https://git.yaegashi.fr/nishiki/ansible-role-phpfpm/releases) +[](https://git.yaegashi.fr/nishiki/ansible-role-phpfpm/releases) [](https://travis-ci.org/nishiki/ansible-role-phpfpm) [](https://git.yaegashi.fr/nishiki/ansible-role-phpfpm/src/branch/master/LICENSE) @@ -7,7 +7,7 @@ Install and configure PHP FPM ## Requirements -* Ansible >= 2.5 +* Ansible >= 2.4 * Debian Stretch ## Role variables @@ -33,6 +33,7 @@ Install and configure PHP FPM See [php pool directives documentation](http://php.net/manual/en/install.fpm.configuration.php) +* `phpfpm_group` - (default: `www-data`) * `phpfpm_ping_path` - (default: `/ping`) * `phpfpm_ping_response` - (default: `pong`) * `phpfpm_pm` - (default: `ondemand`) diff --git a/defaults/main.yml b/defaults/main.yml index 6682c5c..690e99c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,5 @@ ---- phpfpm_version: 7.0 +phpfpm_group: www-data phpfpm_dir: /etc/php/{{ phpfpm_version }}/fpm phpfpm_dir_log: /var/log/phpfpm phpfpm_packages: diff --git a/handlers/main.yml b/handlers/main.yml index 6543315..2ab3f34 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,4 +1,3 @@ ---- - name: reload php-fpm systemd: name: 'php{{ phpfpm_version }}-fpm' diff --git a/meta/main.yml b/meta/main.yml deleted file mode 100644 index 9384a93..0000000 --- a/meta/main.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -galaxy_info: - role_name: phpfpm - author: Adrien Waksberg - company: Adrien Waksberg - description: Install and configure PHP-FPM - license: Apache2 - min_ansible_version: 2.5 - - platforms: - - name: Debian - versions: - - stretch - - galaxy_tags: - - php - - fpm - - web - -dependencies: [] diff --git a/tasks/base.yml b/tasks/base.yml index ecd3651..7d43b6b 100644 --- a/tasks/base.yml +++ b/tasks/base.yml @@ -1,4 +1,3 @@ ---- - name: install php-fpm package package: name: 'php{{ phpfpm_version }}-fpm' @@ -6,7 +5,8 @@ - name: install additionnal packages package: - name: '{{ phpfpm_packages }}' + name: '{{ item }}' + with_items: '{{ phpfpm_packages }}' tags: phpfpm - name: create log directory diff --git a/tasks/main.yml b/tasks/main.yml index 490eb5f..1784c2f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,9 +1,6 @@ ---- -- import_tasks: base.yml - tags: phpfpm +- include_tasks: base.yml -- import_tasks: pools.yml - tags: phpfpm +- include_tasks: pools.yml - name: enable and start php-fpm systemd: diff --git a/tasks/pools.yml b/tasks/pools.yml index 39393cd..eced0f8 100644 --- a/tasks/pools.yml +++ b/tasks/pools.yml @@ -1,13 +1,38 @@ ---- +- name: create user for php-fpm with a specify uid + user: + name: '{{ item.user }}' + group: '{{ item.group|default(phpfpm_group) }}' + uid: '{{ item.uid }}' + home: '{{ item.home }}' + with_items: '{{ phpfpm_pools }}' + when: item.uid is defined + tags: phpfpm + +- name: create user for php-fpm without a specify uid + user: + name: '{{ item.user }}' + group: '{{ item.group|default(phpfpm_group) }}' + home: '{{ item.home }}' + with_items: '{{ phpfpm_pools }}' + when: not item.uid is defined + tags: phpfpm + +- name: set attributes on homes directories + file: + path: '{{ item.home }}' + owner: '{{ item.user }}' + group: www-data + mode: 0750 + state: directory + with_items: '{{ phpfpm_pools }}' + tags: phpfpm + - name: check if pools log files exist stat: path: '{{ phpfpm_dir_log }}/{{ item[0].name }}.{{ item[1] }}' - loop: '{{ phpfpm_pools|product(log_files)|list }}' - vars: - log_files: - - slow.log - - access.log - - log + with_nested: + - '{{ phpfpm_pools }}' + - ['slow.log', 'access.log', 'log'] register: st tags: phpfpm @@ -18,7 +43,7 @@ group: www-data mode: 0640 state: touch - loop: '{{ st.results }}' + with_items: '{{ st.results }}' when: not item.stat.exists tags: phpfpm diff --git a/templates/pools.conf.j2 b/templates/pools.conf.j2 index 028a7d9..fc4f0eb 100644 --- a/templates/pools.conf.j2 +++ b/templates/pools.conf.j2 @@ -4,11 +4,11 @@ [{{ pool.name }}] user = {{ pool.user }} -group = {{ pool.group|default(pool.user) }} +group = {{ pool.group|default(phpfpm_group) }} listen = /var/run/php{{ phpfpm_version }}-fpm-{{ pool.name }}.sock listen.owner = {{ pool.user }} -listen.group = www-data +listen.group = {{ pool.group|default(phpfpm_group) }} pm = {{ pool.pm|default(phpfpm_pm) }} pm.max_children = {{ pool.pm_max_children|default(phpfpm_pm_max_children) }} diff --git a/test/integration/phpfpm/default.yml b/test/integration/phpfpm/default.yml index 2c6f213..aab9553 100644 --- a/test/integration/phpfpm/default.yml +++ b/test/integration/phpfpm/default.yml @@ -1,18 +1,11 @@ ---- - hosts: localhost connection: local vars: phpfpm_pools: - - name: website1 + - name: www user: www - - name: website2 - user: www - pm: static - pm_max_children: 4 - - pre_tasks: - - user: - name: www + home: /opt/www + uid: 1001 roles: - ansible-role-phpfpm diff --git a/test/integration/phpfpm/serverspec/phpfpm_spec.rb b/test/integration/phpfpm/serverspec/phpfpm_spec.rb index c57f615..5b883be 100644 --- a/test/integration/phpfpm/serverspec/phpfpm_spec.rb +++ b/test/integration/phpfpm/serverspec/phpfpm_spec.rb @@ -40,11 +40,10 @@ describe file('/etc/php/7.0/fpm/pools.conf') do it { should be_owned_by 'root' } it { should be_grouped_into 'root' } its(:content) { should match(/pm\s+= ondemand/) } - its(:content) { should match(/pm\s+= static/) } end %w[slow.log access.log log].each do |ext| - describe file("/var/log/phpfpm/website1.#{ext}") do + describe file("/var/log/phpfpm/www.#{ext}") do it { should be_file } it { should be_mode 640 } it { should be_owned_by 'root' } @@ -56,12 +55,3 @@ describe service('php7.0-fpm') do it { should be_enabled } it { should be_running.under('systemd') } end - - -describe process('php-fpm: pool website1') do - its(:count) { should eq 0 } -end - -describe process('php-fpm: pool website2') do - its(:count) { should eq 4 } -end