From a107ed74182b32d6fdc6f1ab8cd1fe5b175100d1 Mon Sep 17 00:00:00 2001 From: Bodo Schulz Date: Fri, 9 Dec 2022 11:38:31 +0100 Subject: [PATCH] add ansible fqdn --- .ansible-lint | 4 +- .editorconfig | 3 + .github/workflows/galaxy.yml | 30 ++++++ .github/workflows/linter.yml | 33 ++++++ .github/workflows/main.yml | 121 ++++++++-------------- .yamllint | 43 +++++--- Makefile | 4 +- defaults/main.yml | 36 +++---- handlers/main.yml | 9 +- hooks/_tox_base | 9 ++ hooks/converge | 9 +- hooks/destroy | 9 +- hooks/lint | 9 +- hooks/verify | 9 +- meta/main.yml | 4 +- molecule/default/group_vars/all/vars.yaml | 3 + molecule/default/molecule.yml | 12 +-- molecule/default/tests/test_default.py | 2 +- molecule/with-redis/tests/test_default.py | 2 +- tasks/download.yaml | 5 +- tasks/install.yaml | 33 +++--- tasks/main.yaml | 11 +- tasks/prepare.yaml | 45 ++++---- tasks/service.yaml | 4 +- test-requirements.txt | 19 ++-- tox.ini | 29 ++---- 26 files changed, 267 insertions(+), 230 deletions(-) create mode 100644 .github/workflows/galaxy.yml create mode 100644 .github/workflows/linter.yml create mode 100644 hooks/_tox_base create mode 100644 molecule/default/group_vars/all/vars.yaml diff --git a/.ansible-lint b/.ansible-lint index 02e672e..48763f0 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,5 +1,5 @@ --- skip_list: - - role-name -# - yaml + - name[casing] + - name[template] diff --git a/.editorconfig b/.editorconfig index 84a63e4..36a81fd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,9 @@ trim_trailing_whitespace = true insert_final_newline = true max_line_length = 100 +[*.py] +indent_size = 4 + [*.md] trim_trailing_whitespace = false diff --git a/.github/workflows/galaxy.yml b/.github/workflows/galaxy.yml new file mode 100644 index 0000000..199cbf4 --- /dev/null +++ b/.github/workflows/galaxy.yml @@ -0,0 +1,30 @@ +--- + +name: push to ansible galaxy + +on: + workflow_dispatch: + workflow_run: + workflows: + - "CI" + branches: + - main + types: + - completed + +jobs: + galaxy: + name: galaxy + runs-on: ubuntu-20.04 + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Check out the codebase + uses: actions/checkout@v3 + with: + path: 'ansible-algernon' + + - name: galaxy + uses: robertdebock/galaxy-action@1.2.1 + with: + galaxy_api_key: ${{ secrets.galaxy_api_key }} + git_branch: main diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..e968761 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,33 @@ +--- + +name: code linter + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + - testing + +jobs: + lint: + name: linting + runs-on: ubuntu-latest + steps: + - name: 🛎 Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: lint + uses: docker://ghcr.io/github/super-linter:slim-v4 + env: + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GH_REGISTRY_TOKEN }} + VALIDATE_ALL_CODEBASE: true + VALIDATE_ANSIBLE: true + # VALIDATE_MARKDOWN: true + VALIDATE_YAML: true + +... diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e1fb445..6ede381 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,63 +2,49 @@ name: CI on: - pull_request: - push: - branches: - - main schedule: - cron: "0 2 * * 0" + workflow_dispatch: + workflow_run: + workflows: + - "code linter" + branches: + - main + - feature + types: + - completed defaults: run: working-directory: 'ansible-algernon' jobs: - lint: - name: linting - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: lint - uses: docker://ghcr.io/github/super-linter:slim-v4 - env: - # DEFAULT_BRANCH: main - GITHUB_TOKEN: ${{ secrets.GH_REGISTRY_TOKEN }} - VALIDATE_ALL_CODEBASE: true - VALIDATE_ANSIBLE: true - # VALIDATE_MARKDOWN: true - VALIDATE_YAML: true arch: - name: "${{ matrix.image }} / python: ${{ matrix.python-version }}, ansible: ${{ matrix.ansible-version }}" - needs: - - lint - runs-on: ubuntu-18.04 + name: "${{ matrix.image }} / ansible: ${{ matrix.ansible-version }}" + runs-on: ubuntu-20.04 + if: ${{ github.event_name == 'schedule' || github.event.workflow_run.conclusion == 'success' }} strategy: fail-fast: false matrix: image: - archlinux:latest - python-version: - - '3.9' + # - artixlinux:latest ansible-version: - - '4.1.0' - - '5.1.0' + - '5.10' + - '6.7' + - '7.0' steps: - name: check out the codebase. - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: 'ansible-algernon' - - name: set up python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - name: 🐍 set up python + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: '3.x' - name: install dependencies run: | @@ -67,17 +53,17 @@ jobs: - name: test with tox run: | - tox -e py$(printf "${{ matrix.python-version }}" | tr -d '.')-ansible$(printf "${{ matrix.ansible-version }}" | tr -d '.') -- molecule test + tox -e ansible_$(printf "${{ matrix.ansible-version }}") \ + -- molecule test --scenario-name default env: PY_COLORS: '1' ANSIBLE_FORCE_COLOR: '1' DISTRIBUTION: ${{ matrix.image }} deb: - name: "${{ matrix.image }} / python: ${{ matrix.python-version }}, ansible: ${{ matrix.ansible-version }}" - needs: - - lint - runs-on: ubuntu-18.04 + name: "${{ matrix.image }} / ansible: ${{ matrix.ansible-version }}" + runs-on: ubuntu-20.04 + if: ${{ github.event_name == 'schedule' || github.event.workflow_run.conclusion == 'success' }} strategy: fail-fast: false matrix: @@ -85,22 +71,21 @@ jobs: - debian:10 - debian:11 - ubuntu:20.04 - python-version: - - '3.9' ansible-version: - - '4.1.0' - - '5.1.0' + - '5.10' + - '6.7' + - '7.0' steps: - name: check out the codebase. - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: 'ansible-algernon' - - name: set up python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - name: 🐍 set up python + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: '3.x' - name: install dependencies run: | @@ -109,17 +94,17 @@ jobs: - name: test with tox run: | - tox -e py$(printf "${{ matrix.python-version }}" | tr -d '.')-ansible$(printf "${{ matrix.ansible-version }}" | tr -d '.') -- molecule test + tox -e ansible_$(printf "${{ matrix.ansible-version }}") \ + -- molecule test --scenario-name default env: PY_COLORS: '1' ANSIBLE_FORCE_COLOR: '1' DISTRIBUTION: ${{ matrix.image }} rpm: - name: "${{ matrix.image }} / python: ${{ matrix.python-version }}, ansible: ${{ matrix.ansible-version }}" - needs: - - lint - runs-on: ubuntu-18.04 + name: "${{ matrix.image }} / ansible: ${{ matrix.ansible-version }}" + runs-on: ubuntu-20.04 + if: ${{ github.event_name == 'schedule' || github.event.workflow_run.conclusion == 'success' }} strategy: fail-fast: false matrix: @@ -127,22 +112,21 @@ jobs: - oraclelinux:8 - rockylinux:8 - almalinux:8 - python-version: - - '3.9' ansible-version: - - '4.1.0' - - '5.1.0' + - '5.10' + - '6.7' + - '7.0' steps: - name: check out the codebase. - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: 'ansible-algernon' - - name: set up python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - name: 🐍 set up python + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: '3.x' - name: install dependencies run: | @@ -151,22 +135,9 @@ jobs: - name: test with tox run: | - tox -e py$(printf "${{ matrix.python-version }}" | tr -d '.')-ansible$(printf "${{ matrix.ansible-version }}" | tr -d '.') -- molecule test + tox -e ansible_$(printf "${{ matrix.ansible-version }}") \ + -- molecule test --scenario-name default env: PY_COLORS: '1' ANSIBLE_FORCE_COLOR: '1' DISTRIBUTION: ${{ matrix.image }} - - publish: - if: github.ref == 'refs/heads/main' - needs: - - arch - - deb - - rpm - runs-on: ubuntu-18.04 - steps: - - name: galaxy - uses: robertdebock/galaxy-action@1.2.0 - with: - galaxy_api_key: ${{ secrets.galaxy_api_key }} - git_branch: main diff --git a/.yamllint b/.yamllint index 2db949b..8bbe487 100644 --- a/.yamllint +++ b/.yamllint @@ -1,25 +1,36 @@ --- +# Based on ansible-lint config extends: default + rules: - line-length: - max: 195 - level: warning - braces: - min-spaces-inside: 0 + braces: max-spaces-inside: 1 + level: error brackets: - min-spaces-inside: 0 max-spaces-inside: 1 - indentation: - spaces: 2 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error comments: disable comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: + spaces: 2 + key-duplicates: enable + line-length: + max: 195 + level: warning + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable truthy: disable - -ignore: | - tests/ - molecule/ - .molecule/ - .travis.yml - .tox - .github diff --git a/Makefile b/Makefile index 6c4b2c2..40857c8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # export TOX_SCENARIO ?= default -export TOX_PYTHON ?= py310 -export TOX_ANSIBLE ?= ansible510 +# export TOX_PYTHON ?= py310 +export TOX_ANSIBLE ?= ansible_6.1 .PHONY: converge destroy verify lint diff --git a/defaults/main.yml b/defaults/main.yml index f67aeee..5fa62e0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,6 @@ --- -algernon_version: '1.13.0' +algernon_version: '1.14.0' algernon_direct_download: false @@ -14,22 +14,22 @@ algernon_data_directory: /var/www/algernon algernon_listen_port: 8090 algernon_listen_address: '127.0.0.1' -algernon_config: - listen: - address: "{{ algernon_listen_address }}" - port: "{{ algernon_listen_port }}" - data_directory: "{{ algernon_data_directory }}" - # Sets a cache mode. The default is "on". - # "on" - Cache everything. - # "dev" - Everything, except Amber, - # Lua, GCSS, Markdown and JSX. - # "prod" - Everything, except Amber and Lua. - # "small" - Like "prod", but only files <= 64KB. - # "images" - Only images (png, jpg, gif, svg). - # "off" - Disable caching. - cache: "on" - # for redis support set HOST:PORT, e.g. 127.0.0.1:6379 - redis: - host: 127.0.0.1 +algernon_config: {} +# listen: +# address: "{{ algernon_listen_address }}" +# port: "{{ algernon_listen_port }}" +# data_directory: "{{ algernon_data_directory }}" +# # Sets a cache mode. The default is "on". +# # "on" - Cache everything. +# # "dev" - Everything, except Amber, +# # Lua, GCSS, Markdown and JSX. +# # "prod" - Everything, except Amber and Lua. +# # "small" - Like "prod", but only files <= 64KB. +# # "images" - Only images (png, jpg, gif, svg). +# # "off" - Disable caching. +# cache: "on" +# # for redis support set HOST:PORT, e.g. 127.0.0.1:6379 +# redis: +# host: 127.0.0.1 ... diff --git a/handlers/main.yml b/handlers/main.yml index 0091a8b..5a313c4 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,15 +1,16 @@ --- - name: restart algernon - service: + ansible.builtin.service: name: algernon state: restarted - name: daemon-reload - systemd: + become: true + ansible.builtin.systemd: daemon_reload: true force: true - notify: - - restart algernon + when: + - ansible_service_mgr | lower == "systemd" ... diff --git a/hooks/_tox_base b/hooks/_tox_base new file mode 100644 index 0000000..a15f7c3 --- /dev/null +++ b/hooks/_tox_base @@ -0,0 +1,9 @@ + +TOX_ARGS= + +if [ -n "${TOX_SCENARIO}" ] +then + TOX_ARGS="--scenario-name ${TOX_SCENARIO}" +fi + +TOX_OPTS="-e ${TOX_ANSIBLE}" diff --git a/hooks/converge b/hooks/converge index d78e38a..5df5ad6 100755 --- a/hooks/converge +++ b/hooks/converge @@ -1,10 +1,5 @@ #!/usr/bin/env bash -TOX_ARGS= +. hooks/_tox_base -if [ -n "${TOX_SCENARIO}" ] -then - TOX_ARGS="--scenario-name ${TOX_SCENARIO}" -fi - -tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule converge ${TOX_ARGS} # -- -v +tox ${TOX_OPTS} -- molecule converge ${TOX_ARGS} diff --git a/hooks/destroy b/hooks/destroy index d7cda5f..98fcf16 100755 --- a/hooks/destroy +++ b/hooks/destroy @@ -1,10 +1,5 @@ #!/usr/bin/env bash -TOX_ARGS= +. hooks/_tox_base -if [ -n "${TOX_SCENARIO}" ] -then - TOX_ARGS="--scenario-name ${TOX_SCENARIO}" -fi - -tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule destroy ${TOX_ARGS} +tox ${TOX_OPTS} -- molecule destroy ${TOX_ARGS} diff --git a/hooks/lint b/hooks/lint index 7fac485..6cf7ff3 100755 --- a/hooks/lint +++ b/hooks/lint @@ -1,10 +1,5 @@ #!/usr/bin/env bash -TOX_ARGS= +. hooks/_tox_base -if [ -n "${TOX_SCENARIO}" ] -then - TOX_ARGS="--scenario-name ${TOX_SCENARIO}" -fi - -tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule lint ${TOX_ARGS} +tox ${TOX_OPTS} -- molecule lint ${TOX_ARGS} diff --git a/hooks/verify b/hooks/verify index 540f8d3..79a38d4 100755 --- a/hooks/verify +++ b/hooks/verify @@ -1,10 +1,5 @@ #!/usr/bin/env bash -TOX_ARGS= +. hooks/_tox_base -if [ -n "${TOX_SCENARIO}" ] -then - TOX_ARGS="--scenario-name ${TOX_SCENARIO}" -fi - -tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule verify ${TOX_ARGS} +tox ${TOX_OPTS} -- molecule verify ${TOX_ARGS} diff --git a/meta/main.yml b/meta/main.yml index bd23be3..2d50c27 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -8,7 +8,7 @@ galaxy_info: description: installs and configure algernon license: Apache - min_ansible_version: 2.9 + min_ansible_version: "2.10" platforms: - name: ArchLinux - name: Debian @@ -23,7 +23,7 @@ galaxy_info: - focal - name: EL versions: - - 8 + - "8" galaxy_tags: - server diff --git a/molecule/default/group_vars/all/vars.yaml b/molecule/default/group_vars/all/vars.yaml new file mode 100644 index 0000000..c81cf5b --- /dev/null +++ b/molecule/default/group_vars/all/vars.yaml @@ -0,0 +1,3 @@ +--- + +... diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 0f9d9df..47202c9 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -13,7 +13,7 @@ lint: | platforms: - name: instance - image: "bodsch/ansible-${DISTRIBUTION:-debian:10}" + image: "bodsch/ansible-${DISTRIBUTION:-debian:11}" command: ${MOLECULE_DOCKER_COMMAND:-""} docker_host: "${DOCKER_HOST:-unix://run/docker.sock}" privileged: true @@ -23,17 +23,17 @@ platforms: provisioner: name: ansible - # ansible_args: - # - --diff - # # - -vvv + ansible_args: + - --diff + # - -vv config_options: defaults: - deprecation_warnings: True + deprecation_warnings: true stdout_callback: yaml scenario: test_sequence: - - lint + # - lint - destroy - dependency - syntax diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 13be3f7..9d50366 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -28,7 +28,7 @@ def base_directory(): """ ... """ cwd = os.getcwd() - if('group_vars' in os.listdir(cwd)): + if ('group_vars' in os.listdir(cwd)): directory = "../.." molecule_directory = "." else: diff --git a/molecule/with-redis/tests/test_default.py b/molecule/with-redis/tests/test_default.py index 13be3f7..9d50366 100644 --- a/molecule/with-redis/tests/test_default.py +++ b/molecule/with-redis/tests/test_default.py @@ -28,7 +28,7 @@ def base_directory(): """ ... """ cwd = os.getcwd() - if('group_vars' in os.listdir(cwd)): + if ('group_vars' in os.listdir(cwd)): directory = "../.." molecule_directory = "." else: diff --git a/tasks/download.yaml b/tasks/download.yaml index 76b9ca1..5a521fb 100644 --- a/tasks/download.yaml +++ b/tasks/download.yaml @@ -3,9 +3,10 @@ - name: download algernon archive become: false delegate_to: "{{ algernon_delegate_to }}" - get_url: + ansible.builtin.get_url: url: "https://github.com/xyproto/algernon/releases/download/{{ algernon_remote_version }}/{{ algernon_archive_name }}" dest: "{{ algernon_local_tmp_directory }}/algernon-{{ algernon_version }}-linux.tar.xz" + mode: 0600 register: _download_archive until: _download_archive is succeeded retries: 5 @@ -15,7 +16,7 @@ - name: extract algernon archive become: false delegate_to: "{{ algernon_delegate_to }}" - unarchive: + ansible.builtin.unarchive: src: "{{ algernon_local_tmp_directory }}/algernon-{{ algernon_version }}-linux.tar.xz" dest: "{{ algernon_local_tmp_directory }}" copy: false diff --git a/tasks/install.yaml b/tasks/install.yaml index 9a7ecc3..a34409e 100644 --- a/tasks/install.yaml +++ b/tasks/install.yaml @@ -3,13 +3,16 @@ - name: detect binary file for algernon become: false delegate_to: "{{ algernon_delegate_to }}" - stat: + ansible.builtin.stat: path: "{{ algernon_local_tmp_directory }}/algernon-{{ algernon_version }}-linux_{{ ansible_architecture }}_static/algernon" register: stat_file_binary -- block: +- name: copy binaries + when: + - stat_file_binary.stat.exists + block: - name: propagate algernon binaries - copy: + ansible.builtin.copy: src: "{{ algernon_local_tmp_directory }}/algernon-{{ algernon_version }}-linux_{{ ansible_architecture }}_static/algernon" dest: "{{ algernon_install_path }}/algernon" mode: 0755 @@ -18,22 +21,20 @@ remote_src: "{{ 'true' if algernon_direct_download else 'false' }}" - name: make files executable - file: + ansible.builtin.file: path: "{{ algernon_install_path }}/algernon" mode: 0755 owner: "{{ algernon_system_user }}" group: "{{ algernon_system_group }}" - when: - - stat_file_binary.stat.exists - name: create local facts - template: + ansible.builtin.template: src: ansible_facts.j2 dest: /etc/ansible/facts.d/algernon.fact mode: 0755 - name: create data directory - file: + ansible.builtin.file: path: "{{ algernon_data_directory }}" state: directory owner: "{{ algernon_system_user }}" @@ -41,14 +42,17 @@ mode: 0755 - name: logfile + when: + - algernon_config.access_log is defined + - algernon_config.access_log | length > 0 block: - name: detect logfile - stat: + ansible.builtin.stat: path: "{{ algernon_config.access_log }}" register: _logfile_exists - name: create logfile - file: + ansible.builtin.file: path: "{{ algernon_config.access_log }}" state: touch owner: "{{ algernon_system_user }}" @@ -57,12 +61,9 @@ run_once: true when: - not _logfile_exists.stat.exists | default('false') - when: - - algernon_config.access_log is defined - - algernon_config.access_log | length > 0 - name: create link to binary - file: + ansible.builtin.file: src: "{{ algernon_install_path }}/algernon" dest: /usr/bin/algernon state: link @@ -72,7 +73,7 @@ - restart algernon - name: create the systemd service file - template: + ansible.builtin.template: src: init/systemd/algernon.service.j2 dest: "{{ systemd_lib_directory }}/algernon.service" owner: root @@ -82,7 +83,7 @@ - daemon-reload - name: create the systemd service config file - template: + ansible.builtin.template: src: algernon.conf.j2 dest: "{{ algernon_config_directory }}/algernon" owner: root diff --git a/tasks/main.yaml b/tasks/main.yaml index 8b3b805..ba11249 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -1,21 +1,24 @@ --- -- import_tasks: prepare.yaml +- name: prepare + ansible.builtin.import_tasks: prepare.yaml become: true tags: - algernon_prepare - name: download - include_tasks: download.yaml + ansible.builtin.include_tasks: download.yaml when: - not stat_algernon_binary.stat.exists -- import_tasks: install.yaml +- name: install + ansible.builtin.import_tasks: install.yaml become: true tags: - algernon_install -- import_tasks: service.yaml +- name: service + ansible.builtin.import_tasks: service.yaml become: true tags: - algernon_service diff --git a/tasks/prepare.yaml b/tasks/prepare.yaml index 993aac2..124a236 100644 --- a/tasks/prepare.yaml +++ b/tasks/prepare.yaml @@ -1,7 +1,7 @@ --- - name: include OS specific configuration ({{ ansible_distribution }} ({{ ansible_os_family }}) {{ ansible_distribution_major_version }}) - include_vars: "{{ lookup('first_found', params) }}" + ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" vars: params: paths: @@ -17,24 +17,24 @@ skip: true - name: update package cache - package: + ansible.builtin.package: update_cache: true - name: dependecies + when: + - algernon_requirements is defined + - algernon_requirements | count > 0 block: - name: install dependency - package: + ansible.builtin.package: name: "{{ algernon_requirements }}" state: present - name: update facts to get latest information - setup: - when: - - algernon_requirements is defined - - algernon_requirements | count > 0 + ansible.builtin.setup: - name: define delegate instance for download handling - set_fact: + ansible.builtin.set_fact: algernon_delegate_to: "{{ ansible_host }}" algernon_local_tmp_directory: "{{ lookup('env', 'CUSTOM_LOCAL_TMP_DIRECTORY') | @@ -44,36 +44,38 @@ - algernon_direct_download - name: detect our installation path '{{ algernon_install_path | dirname }}' - stat: + ansible.builtin.stat: path: "{{ algernon_install_path | dirname }}" get_checksum: false register: stat_algernon_path ignore_errors: true - name: detect installed algernon binary - stat: + ansible.builtin.stat: path: "{{ algernon_install_path }}/algernon" register: stat_algernon_binary - name: create download directory become: false delegate_to: "{{ algernon_delegate_to }}" - file: + ansible.builtin.file: path: "{{ algernon_local_tmp_directory }}" state: directory mode: 0750 run_once: "{{ 'true' if not algernon_direct_download else 'false' }}" - name: user and group handling + when: + - algernon_system_user != "root" block: - name: create algernon group - group: + ansible.builtin.group: name: "{{ algernon_system_group }}" state: present system: true - name: create algernon user - user: + ansible.builtin.user: name: "{{ algernon_system_user }}" groups: "{{ algernon_system_group }}" append: true @@ -81,11 +83,9 @@ system: true createhome: false home: /nonexistent - when: - - algernon_system_user != "root" - name: create install directory - file: + ansible.builtin.file: path: "{{ algernon_install_path }}" state: directory owner: "{{ algernon_system_user }}" @@ -93,7 +93,7 @@ mode: 0755 - name: create ansible local facts directory - file: + ansible.builtin.file: dest: /etc/ansible/facts.d state: directory owner: root @@ -101,12 +101,11 @@ mode: 0775 - name: merge algernon configuration between defaults and custom - set_fact: - algernon_config: "{{ algernon_defaults_config | - combine( algernon_config, recursive=True ) }}" + ansible.builtin.set_fact: + algernon_config: "{{ algernon_defaults_config | combine(algernon_config, recursive=True) }}" - name: re-define archive name for 1.12.x - set_fact: + ansible.builtin.set_fact: algernon_archive_name: algernon-{{ algernon_version }}-linux_static.tar.xz algernon_remote_version: "{{ algernon_version }}" when: @@ -114,10 +113,10 @@ - algernon_version_patch | int > 10 - name: re-define archive name for 1.13.x - set_fact: + ansible.builtin.set_fact: algernon_archive_name: algernon-{{ algernon_version }}-linux_{{ ansible_architecture }}_static.tar.xz algernon_remote_version: "v{{ algernon_version }}" when: - - algernon_version_minor | int == 13 + - algernon_version_minor | int >= 13 ... diff --git a/tasks/service.yaml b/tasks/service.yaml index c3ba411..5bdd0a9 100644 --- a/tasks/service.yaml +++ b/tasks/service.yaml @@ -1,11 +1,11 @@ --- - name: restart algernon if needed - meta: flush_handlers + ansible.builtin.meta: flush_handlers - name: ensure algernon is enabled on boot become: true - service: + ansible.builtin.service: name: algernon enabled: true state: started diff --git a/test-requirements.txt b/test-requirements.txt index b6b224c..813e694 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,10 +1,11 @@ ansible-lint==5.4.0 -molecule==3.6.1 -molecule-docker==1.1.0 -docker==5.0.0 -yamllint==1.26.3 -flake8==3.9.2 -pytest==6.2.5 -pytest-testinfra==6.4.0 -tox==3.24.3 -tox-gh-actions==2.6.0 +molecule==4.0.1 +molecule-docker==2.0.0 +docker==5.0.3 +yamllint==1.27.1 +flake8==4.0.1 +pytest==7.1.2 +pytest-testinfra==6.8.0 +tox==3.25.1 +tox-gh-actions==2.9.1 +netaddr==0.8.0 diff --git a/tox.ini b/tox.ini index 1f8d085..e6192d4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,34 +1,25 @@ [tox] -minversion = 1.8 +minversion = 3.25 toxworkdir = /tmp/.tox/ -envlist = py{39,310}-ansible{29,210} +envlist = ansible_{2.9,2.10,3.4,4.10,5.1,5.2,6.1} skipsdist = true -[gh-actions] -ansible = - 2.9: ansible29 - 2.10: ansible210 - -python = - 3.9: py39 - 3.10: py310 - [testenv] passenv = * deps = -r test-requirements.txt - ansible210: ansible>=2.10,<2.11 - ansible340: ansible>=3.4,<3.5 - ansible410: ansible>=4.10,<4.11 - ansible510: ansible>=5.1,<5.2 - ansible520: ansible>=5.2,<5.3 - ansible530: ansible>=5.3,<5.4 - ansible540: ansible>=5.4,<5.5 + ansible_4.10: ansible>=4.10,<4.11 + ansible_5.1: ansible>=5.1,<5.2 + ansible_5.2: ansible>=5.2,<5.3 + ansible_5.10: ansible>=5.10,<5.11 + ansible_6.1: ansible>=6.1,<6.2 + ansible_6.7: ansible>=6.7,<6.8 + ansible_7.0: ansible>=7.0,<7.1 commands_pre = - /usr/bin/find {toxinidir} -type f -not -path '{toxinidir}/.tox/*' -path '*/__pycache__/*' -name '*.py[c|o]' -delete + /usr/bin/find {toxinidir} -type f -not -path '{toxworkdir}/*' -path '*/__pycache__/*' -name '*.py[c|o]' -delete /bin/sh -c '/usr/bin/find {homedir}/.cache -type d -path "*/molecule_*" -exec rm -rfv \{\} +;' commands =