From 9e675bde50a153ad875988842899495e97b6f8d1 Mon Sep 17 00:00:00 2001 From: Dennis Conrad Date: Fri, 11 Jun 2021 16:12:06 +0100 Subject: [PATCH] ansible-lint Test --- .editorconfig | 1 + .pre-commit-config.yaml | 47 ++++++++++++++++++----------------- .travis.yml | 17 ++++++------- .version | 2 +- .yamllint | 35 ++++++++++++++++++++++++++ LICENSE | 2 +- Makefile | 20 +++++++-------- README.md | 13 ++++++++++ meta/main.yml | 6 ++--- molecule/default/molecule.yml | 30 +++++++--------------- molecule/default/prepare.yml | 12 +++++++++ molecule/php7/molecule.yml | 27 +++++++------------- molecule/php7/prepare.yml | 12 +++++++++ requirements.txt | 11 +++++--- tasks/build.yml | 6 +---- tasks/build/fpm.yml | 6 +++-- tasks/build/pecl.yml | 7 ++++++ tasks/configure.yml | 2 ++ 18 files changed, 157 insertions(+), 99 deletions(-) create mode 100644 .yamllint diff --git a/.editorconfig b/.editorconfig index 307d5c6..61bed73 100644 --- a/.editorconfig +++ b/.editorconfig @@ -23,6 +23,7 @@ max_line_length = 119 [*.{js,json,yaml,yml}] indent_size = 2 +insert_final_newline = true [Makefile] indent_style = tab diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ffb2d61..d3a80c3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,26 +1,27 @@ --- -- repo: https://github.com/willthames/ansible-lint.git - sha: v3.4.17 - hooks: - - id: ansible-lint - types: [yaml] - exclude: > - (?x)^( - \.travis\.yml| - molecule/.*/\.molecule/.*| - molecule/.*/create\.yml - )$ - - id: ansible-lint - files: \.travis\.yml - args: [-x, ANSIBLE0008] - - id: ansible-lint - files: molecule/.*/create\.yml - args: [-x, ANSIBLE0016] +repos: + - repo: https://github.com/willthames/ansible-lint.git + rev: v4.2.0 + hooks: + - id: ansible-lint + types: [yaml] + exclude: > + (?x)^( + \.travis\.yml| + molecule/.*/\.molecule/.*| + molecule/.*/create\.yml + )$ + - id: ansible-lint + files: \.travis\.yml + args: [-x, ANSIBLE0008] + - id: ansible-lint + files: molecule/.*/create\.yml + args: [-x, ANSIBLE0016] -- repo: git://github.com/pre-commit/pre-commit-hooks - sha: v0.9.1 - hooks: - - id: check-json - - id: flake8 - - id: trailing-whitespace + - repo: git://github.com/pre-commit/pre-commit-hooks + rev: v2.5.0 + hooks: + - id: check-json + - id: flake8 + - id: trailing-whitespace diff --git a/.travis.yml b/.travis.yml index 0848b24..41eafa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,14 @@ --- group: stable -dist: xenial -sudo: required +dist: bionic + +os: + - linux language: python python: - - 2.7 + - 3.6 cache: pip branches: @@ -15,17 +17,12 @@ branches: - master env: - - ANSIBLE_INSTALL_VERSION=2.5.15 - - ANSIBLE_INSTALL_VERSION=2.6.16 - - ANSIBLE_INSTALL_VERSION=2.7.10 + - ANSIBLE_INSTALL_VERSION=2.8.18 + - ANSIBLE_INSTALL_VERSION=2.9.16 services: - docker -before_install: - - sudo apt-get update -qq - - sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-ce - install: - make deps diff --git a/.version b/.version index 92491a0..62c36de 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -v2.5 +v2.6 diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..da1f64e --- /dev/null +++ b/.yamllint @@ -0,0 +1,35 @@ +--- +# Based on ansible-lint config +extends: default +ignore: .venv_ansible* + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: enable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: enable + key-duplicates: enable + line-length: + max: 159 + new-line-at-end-of-file: enable + new-lines: + type: unix + trailing-spaces: enable + truthy: disable diff --git a/LICENSE b/LICENSE index d46d39c..61f29da 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 +Copyright (c) 2021 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index f3192f2..fe4f524 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -ANSIBLE_INSTALL_VERSION ?= 2.7.10 +ANSIBLE_INSTALL_VERSION ?= 2.9.16 +SCENARIO ?= all PATH := $(PWD)/.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin:$(shell printenv PATH) SHELL := env PATH=$(PATH) /bin/bash @@ -54,26 +55,23 @@ login_%: .venv_ansible$(ANSIBLE_INSTALL_VERSION) ## Run 'molecule test --destroy=never' (run 'make destroy' to destroy containers) test: .venv_ansible$(ANSIBLE_INSTALL_VERSION) - @.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test $(SCENARIO_OPT) --destroy=never - + @if [ "$(SCENARIO_OPT)" == "--all" ]; then \ + echo "Testing all scenarios"; \ + .venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test $(SCENARIO_OPT); \ + else \ + echo "Testing only the $(SCENARIO) scenario"; \ + .venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test $(SCENARIO_OPT) --destroy=never; \ + fi # shortcut for creating venv .venv: .venv_ansible$(ANSIBLE_INSTALL_VERSION) - ## Create virtualenv, install dependencies .venv_ansible$(ANSIBLE_INSTALL_VERSION): - @if (python -V 2>&1 | grep -qv "Python 2.7"); then \ - echo -e "\033[0;31mERROR: Only Python 2.7 is supported at this stage\033[0m"; \ - false; \ - fi virtualenv .venv_ansible$(ANSIBLE_INSTALL_VERSION) .venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/pip install -r requirements.txt --ignore-installed - .venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/pip install ansible==$(ANSIBLE_INSTALL_VERSION) - virtualenv --relocatable .venv_ansible$(ANSIBLE_INSTALL_VERSION) @echo -e "\033[0;32mINFO: Run 'make activate' to activate the virtualenv for this shell\033[0m" - ## Run 'make test' on any file change watch: .venv_ansible$(ANSIBLE_INSTALL_VERSION) @while sleep 1; do \ diff --git a/README.md b/README.md index 819858b..a639cfa 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,19 @@ This role uses one tag: **build** See [defaults/main.yml](defaults/main.yml) +~ + +## Testing + +### Test all scenarios + +`make test` +Note: The test container/s will NOT be left running, so for troubleshooting you may want to specify the scenario as per option below + +### Test a single, specified scenario + +`SCENARIO= make test` +Note: The test container/s WILL be left running. They can be removed with `make destroy` or `make clean`. ## Examples diff --git a/meta/main.yml b/meta/main.yml index 252b698..fa2b01e 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -6,13 +6,13 @@ galaxy_info: author: Sansible description: PHP and FPM installation license: MIT - min_ansible_version: 2.5 - min_ansible_container_version: 2.5 + min_ansible_version: 2.8 + min_ansible_container_version: 2.8 platforms: - name: Ubuntu versions: - - xenial - bionic + - focal galaxy_tags: - development - fpm diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index cffe570..3fa2940 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -4,15 +4,15 @@ driver: name: docker platforms: - - name: sansible_php-xenial - image: solita/ubuntu-systemd:xenial + - name: sansible-php-focal + image: jrei/systemd-ubuntu:20.04 command: /sbin/init capabilities: - SYS_ADMIN volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: sansible_php-bionic - image: solita/ubuntu-systemd:bionic + - name: sansible-php-bionic + image: jrei/systemd-ubuntu:18.04 command: /sbin/init capabilities: - SYS_ADMIN @@ -21,22 +21,12 @@ platforms: provisioner: name: ansible - config_options: - defaults: - hash_behaviour: merge - lint: - name: ansible-lint -lint: - name: yamllint - options: - config-data: - extends: default - ignore: .venv_ansible* - rules: - line-length: - max: 159 - truthy: disable +lint: | + set -e + yamllint . + ansible-lint + flake8 molecule/ dependency: name: galaxy @@ -48,5 +38,3 @@ scenario: verifier: name: testinfra - lint: - name: flake8 diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 4e783d7..24d988f 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -15,6 +15,18 @@ apt: name: - apt-transport-https + - gpg - lsb-release - net-tools + - python3-setuptools + - unzip update_cache: yes + + - name: Symlink pip3 for TestInfra + become: yes + file: + dest: /usr/bin/pip + force: yes + mode: 0751 + src: /usr/bin/pip3 + state: link diff --git a/molecule/php7/molecule.yml b/molecule/php7/molecule.yml index 67b6d07..1fc736b 100644 --- a/molecule/php7/molecule.yml +++ b/molecule/php7/molecule.yml @@ -4,15 +4,15 @@ driver: name: docker platforms: - - name: sansible_php-7-xenial - image: solita/ubuntu-systemd:xenial + - name: sansible-php-7-focal + image: jrei/systemd-ubuntu:20.04 command: /sbin/init capabilities: - SYS_ADMIN volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: sansible_php-7-bionic - image: solita/ubuntu-systemd:bionic + - name: sansible-php-7-bionic + image: jrei/systemd-ubuntu:18.04 command: /sbin/init capabilities: - SYS_ADMIN @@ -21,19 +21,12 @@ platforms: provisioner: name: ansible - lint: - name: ansible-lint -lint: - name: yamllint - options: - config-data: - extends: default - ignore: .venv_ansible* - rules: - line-length: - max: 159 - truthy: disable +lint: | + set -e + yamllint . + ansible-lint + flake8 molecule/ dependency: name: galaxy @@ -45,5 +38,3 @@ scenario: verifier: name: testinfra - lint: - name: flake8 diff --git a/molecule/php7/prepare.yml b/molecule/php7/prepare.yml index 4e783d7..24d988f 100644 --- a/molecule/php7/prepare.yml +++ b/molecule/php7/prepare.yml @@ -15,6 +15,18 @@ apt: name: - apt-transport-https + - gpg - lsb-release - net-tools + - python3-setuptools + - unzip update_cache: yes + + - name: Symlink pip3 for TestInfra + become: yes + file: + dest: /usr/bin/pip + force: yes + mode: 0751 + src: /usr/bin/pip3 + state: link diff --git a/requirements.txt b/requirements.txt index 0ae0aad..7ec0d40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,7 @@ -docker==3.5.1 -flake8==3.7.6 -molecule==2.19.0 -yamllint==1.15.0 \ No newline at end of file +ansible==2.9.16 +ansible-lint==4.3.7 +docker==4.2.2 +flake8==3.8.3 +molecule==3.0.6 +testinfra==5.2.2 +yamllint==1.24.2 diff --git a/tasks/build.yml b/tasks/build.yml index 7eda7ed..8fc3194 100644 --- a/tasks/build.yml +++ b/tasks/build.yml @@ -6,10 +6,6 @@ dest: /usr/local/src/php.asc mode: 0644 url: "{{ sansible_php_repo_keyserver }}/pks/lookup?op=get&search=0x{{ sansible_php_repo_key_id }}" - retries: 2 - delay: 10 - register: sansible_php_pgp_result - until: sansible_php_pgp_result is succeeded - name: Ensures PHP PGP key is known become: yes @@ -33,7 +29,7 @@ - "{{ sansible_php_version }}-common" - "{{ sansible_php_version }}-fpm" - "{{ sansible_php_version }}-cli" - when: sansible_php_install_base_packages == true + when: sansible_php_install_base_packages - name: Install base PHP modules become: yes diff --git a/tasks/build/fpm.yml b/tasks/build/fpm.yml index acb105d..62a1648 100644 --- a/tasks/build/fpm.yml +++ b/tasks/build/fpm.yml @@ -16,6 +16,7 @@ become: yes become_user: "{{ sansible_php_fpm_user }}" file: + mode: 0750 name: "/home/{{ sansible_php_fpm_user }}/{{ item }}" state: directory with_items: @@ -79,9 +80,10 @@ - "/etc/init/{{ sansible_php_version }}-fpm.conf" - "/etc/php/{{ sansible_php_version | replace('php', '') }}/fpm/pool.d/www.conf" -- name: Create fpm status nxinx include +- name: Create fpm status nginx include become: yes template: + mode: 0644 src: fpm_status.j2 dest: "/etc/nginx/includes/{{ sansible_php_fpm_user }}_fpm_status" - when: sansible_php_fpm_nginx_status == true + when: sansible_php_fpm_nginx_status diff --git a/tasks/build/pecl.yml b/tasks/build/pecl.yml index d91923c..dccee3d 100644 --- a/tasks/build/pecl.yml +++ b/tasks/build/pecl.yml @@ -7,6 +7,13 @@ - "{{ sansible_php_version }}-dev" - "{{ sansible_php_version }}-xml" +- name: Update PECL channel + become: yes + ansible.builtin.command: + cmd: pecl channel-update pecl.php.net + register: sansible_php_channel_update_output + changed_when: "'succeeded' in sansible_php_channel_update_output.stdout" + - name: Install PECL modules become: yes pear: diff --git a/tasks/configure.yml b/tasks/configure.yml index 44a6f1c..c04e72a 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -4,6 +4,7 @@ become: yes become_user: "{{ sansible_php_fpm_user }}" template: + mode: 0640 dest: "/home/{{ sansible_php_fpm_user }}/etc/php.ini" src: php.ini.j2 when: sansible_php_fpm_user is not none @@ -12,6 +13,7 @@ become: yes become_user: "{{ sansible_php_fpm_user }}" template: + mode: 0640 dest: "/home/{{ sansible_php_fpm_user }}/etc/php-fpm.conf" src: php-fpm.conf.j2 when: sansible_php_fpm_user is not none