From 3378ca781f7d1bb1432833234b77f3634dc1c141 Mon Sep 17 00:00:00 2001 From: bulch Date: Sun, 15 Dec 2024 12:34:06 +0400 Subject: [PATCH 01/11] fix: role ansible import --- .github/workflows/ci.yml | 19 ------------------- tests/test.yml | 2 +- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b3c2ba..c6b173a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,25 +59,6 @@ jobs: - ubuntu2404 - ubuntu2204 - ubuntu2004 - # - ubuntu1804 # TODO: WARNING Driver docker does not provide a schema - # - ubuntu1604 # TODO: fatal: [instance]: FAILED! => - # { - # "ansible_facts": {}, - # "changed": false, - # "failed_modules": { - # "ansible.legacy.setup": { - # "ansible_facts": { - # "discovered_interpreter_python": "/usr/bin/python3" - # }, - # "failed": true, - # "msg": "ansible-core requires a minimum of Python2 version 2.7 or Python3 version 3.6. Current version: 3.5.2 (default, Jan 26 2021, 13:30:48) [GCC 5.4.0 20160609]" - # } - # }, - # "msg": "The following modules failed to execute: ansible.legacy.setup\n" - # } - # - ubuntu1404 # TODO: ansible-core requires a minimum of Python2 version 2.7 or Python3 version 3.6. Current version: 3.4.3 (default, Nov 28 2017, 16:41:13) [GCC 4.8.4] - # - ubuntu1204 # DEPRECATED https://hub.docker.com/r/geerlingguy/docker-ubuntu1204-ansible - steps: - name: Check out the codebase. uses: actions/checkout@v4.1.6 diff --git a/tests/test.yml b/tests/test.yml index 274422d..a9ff561 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -3,4 +3,4 @@ hosts: molecule-ubuntu remote_user: root roles: - - bulch.rsync_server + - rsync_server From fd81504f7299749081e85fbbb68370afef3ca9f9 Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 00:56:29 +0400 Subject: [PATCH 02/11] feat: bump runs-on ubuntu 24-04 and add ansible-lint --- .ansible-lint | 8 ++++---- .github/workflows/ansible-lint.yml | 27 +++++++++++++++++++++++++++ .github/workflows/ci.yml | 4 ++-- .github/workflows/draft.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- .yamllint | 1 - molecule/default/molecule.yml | 26 +------------------------- tests/test.yml | 2 +- 8 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/ansible-lint.yml diff --git a/.ansible-lint b/.ansible-lint index 8bcbddf..d0e8838 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,7 +1,7 @@ --- -skip_list: - - 'yaml' - - 'risky-shell-pipe' - - 'role-name' +# skip_list: +# - 'yaml' +# - 'risky-shell-pipe' +# - 'role-name' use_default_rules: true verbosity: 1 diff --git a/.github/workflows/ansible-lint.yml b/.github/workflows/ansible-lint.yml new file mode 100644 index 0000000..2154132 --- /dev/null +++ b/.github/workflows/ansible-lint.yml @@ -0,0 +1,27 @@ +name: ansible-lint +# on: +# pull_request: +# branches: ["main", "stable", "release/v*"] +'on': + pull_request: + push: + branches: + - master + - develop + schedule: + - cron: "0 7 * * 0" + +jobs: + build: + name: Ansible Lint # Naming the build is important to use it as a status check + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Run ansible-lint + uses: ansible/ansible-lint@main + # optional (see below): + with: + args: "" + setup_python: "true" + working_directory: "" + requirements_file: "" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6b173a..7cb3d82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: lint: name: Lint - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out the codebase. uses: actions/checkout@v4.1.6 @@ -52,7 +52,7 @@ jobs: molecule: name: Molecule needs: lint - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 strategy: matrix: distro: diff --git a/.github/workflows/draft.yml b/.github/workflows/draft.yml index d20709a..f6345b9 100644 --- a/.github/workflows/draft.yml +++ b/.github/workflows/draft.yml @@ -15,7 +15,7 @@ permissions: jobs: on-failure: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: ${{ github.event.workflow_run.conclusion == 'failure' }} steps: - name: send telegram message on fail build @@ -28,7 +28,7 @@ jobs: See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}} on-success: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: ${{ github.event.workflow_run.conclusion == 'success' }} permissions: pages: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c4be407..adbef3e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: release-ansible-galaxy: name: Release ansible-galaxy - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out the codebase. uses: actions/checkout@v4.1.6 @@ -41,7 +41,7 @@ jobs: srelease-git: name: Release github - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: release-ansible-galaxy steps: - name: 🚀 Create Release version diff --git a/.yamllint b/.yamllint index 66ffa45..ea2b819 100644 --- a/.yamllint +++ b/.yamllint @@ -19,7 +19,6 @@ rules: ignore: | .github/stale.yml - .travis.yml venv .tox .cache/ diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 7db1cd2..9575cdf 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,4 +1,5 @@ --- +role_name_check: 1 dependency: name: galaxy options: @@ -12,37 +13,12 @@ driver: platforms: - name: molecule-ubuntu - # image: ubuntu:18.04 image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest" published_ports: - 0.0.0.0:873:873/tcp exposed_ports: - - 80/tcp - - 443/tcp - 873/tcp -# platforms: -# - name: instance -# image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest" -# exposed_ports: -# - 80/tcp -# - 443/tcp -# published_ports: -# - 0.0.0.0:873:873/tcp -# volumes: -# - /sys/fs/cgroup:/sys/fs/cgroup:rw -# - /dev/null:/dev/null:rw -# # command: /sbin/init -# command: ${MOLECULE_DOCKER_COMMAND:-""} -# tmpfs: -# - /run -# - /tmp -# capabilities: -# - SYS_ADMIN -# cgroupns_mode: host -# privileged: true -# pre_build_image: true - provisioner: name: ansible playbooks: diff --git a/tests/test.yml b/tests/test.yml index a9ff561..0199a54 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -3,4 +3,4 @@ hosts: molecule-ubuntu remote_user: root roles: - - rsync_server + - test-rsync_server From 9df9b2287c07ceafbbaa03d0c7b46730677d8950 Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:13:32 +0400 Subject: [PATCH 03/11] feat: linting --- .github/workflows/ansible-lint.yml | 27 ------------------- .github/workflows/ci.yml | 9 +++++++ molecule/default/molecule.yml | 3 ++- .../roles/test-rsync_server/defaults/main.yml | 4 --- tests/test.yml | 2 +- tests/testrsync_server/defaults/main.yml | 4 +++ .../testrsync_server}/tasks/main.yml | 0 7 files changed, 16 insertions(+), 33 deletions(-) delete mode 100644 .github/workflows/ansible-lint.yml delete mode 100644 molecule/default/roles/test-rsync_server/defaults/main.yml create mode 100644 tests/testrsync_server/defaults/main.yml rename {molecule/default/roles/test-rsync_server => tests/testrsync_server}/tasks/main.yml (100%) diff --git a/.github/workflows/ansible-lint.yml b/.github/workflows/ansible-lint.yml deleted file mode 100644 index 2154132..0000000 --- a/.github/workflows/ansible-lint.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: ansible-lint -# on: -# pull_request: -# branches: ["main", "stable", "release/v*"] -'on': - pull_request: - push: - branches: - - master - - develop - schedule: - - cron: "0 7 * * 0" - -jobs: - build: - name: Ansible Lint # Naming the build is important to use it as a status check - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v4 - - name: Run ansible-lint - uses: ansible/ansible-lint@main - # optional (see below): - with: - args: "" - setup_python: "true" - working_directory: "" - requirements_file: "" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cb3d82..4980a0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,15 @@ jobs: run: | ansible-lint + - name: Run ansible-lint + uses: ansible/ansible-lint@main + # optional (see below): + with: + args: "" + setup_python: "true" + working_directory: "" + requirements_file: "" + molecule: name: Molecule needs: lint diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 9575cdf..4863dff 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -21,9 +21,10 @@ platforms: provisioner: name: ansible + lint: + name: ansible-lint playbooks: converge: ${MOLECULE_PLAYBOOK:-converge.yml} - inventory: host_vars: molecule-ubuntu: diff --git a/molecule/default/roles/test-rsync_server/defaults/main.yml b/molecule/default/roles/test-rsync_server/defaults/main.yml deleted file mode 100644 index 437d967..0000000 --- a/molecule/default/roles/test-rsync_server/defaults/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -path_default_config_rsync: "/etc/default/rsync" -path_secret_rsync: "/etc/rsyncd.secrets" -path_rsync_config: "/etc/rsyncd.conf" diff --git a/tests/test.yml b/tests/test.yml index 0199a54..f1d689b 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -3,4 +3,4 @@ hosts: molecule-ubuntu remote_user: root roles: - - test-rsync_server + - testrsync_server diff --git a/tests/testrsync_server/defaults/main.yml b/tests/testrsync_server/defaults/main.yml new file mode 100644 index 0000000..14641b2 --- /dev/null +++ b/tests/testrsync_server/defaults/main.yml @@ -0,0 +1,4 @@ +--- +testrsync_server_path_default_config_rsync: "/etc/default/rsync" +testrsync_server_path_secret_rsync: "/etc/rsyncd.secrets" +testrsync_server_path_rsync_config: "/etc/rsyncd.conf" diff --git a/molecule/default/roles/test-rsync_server/tasks/main.yml b/tests/testrsync_server/tasks/main.yml similarity index 100% rename from molecule/default/roles/test-rsync_server/tasks/main.yml rename to tests/testrsync_server/tasks/main.yml From fc4aedc3a8dceaadd67ce9f7c7d53b1204ee1afc Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:21:27 +0400 Subject: [PATCH 04/11] fix: lint test --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4980a0d..e314a59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,12 +51,8 @@ jobs: - name: Run ansible-lint uses: ansible/ansible-lint@main - # optional (see below): with: - args: "" setup_python: "true" - working_directory: "" - requirements_file: "" molecule: name: Molecule From e27d380eed03b2e0b57c0636d5756cff1bdcb3bc Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:32:43 +0400 Subject: [PATCH 05/11] feat: set default --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e314a59..05a4179 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,12 @@ jobs: - name: Run ansible-lint uses: ansible/ansible-lint@main + # optional (see below): with: + args: "" setup_python: "true" + working_directory: "github.workspace" + requirements_file: "" molecule: name: Molecule From 16b98d6fcbe8ec3b2b1c201ed3806ab0cfa53bcc Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:37:17 +0400 Subject: [PATCH 06/11] fix: vars --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05a4179..60dbe58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: with: args: "" setup_python: "true" - working_directory: "github.workspace" + working_directory: "${{ github.workspace }}" requirements_file: "" molecule: From 892a647e7770abcec56f0a19d6d2ded2c696f442 Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:43:06 +0400 Subject: [PATCH 07/11] fix: vars --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60dbe58..3c84591 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,8 +55,8 @@ jobs: with: args: "" setup_python: "true" - working_directory: "${{ github.workspace }}" - requirements_file: "" + working_directory: "/home/runner/work/ansible-role-rsync-server" + requirements_file: "requirements.yml" molecule: name: Molecule From e9f1bbd79eb01a1b04562d636a745741ab852010 Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:46:22 +0400 Subject: [PATCH 08/11] fix: remove action not work --- .github/workflows/ci.yml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c84591..8bb92e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,18 +45,12 @@ jobs: run: | yamllint -c=.yamllint . - - name: Lint code ansible-lint. - run: | - ansible-lint - - name: Run ansible-lint - uses: ansible/ansible-lint@main - # optional (see below): - with: - args: "" - setup_python: "true" - working_directory: "/home/runner/work/ansible-role-rsync-server" - requirements_file: "requirements.yml" + run: | + exit_code=0 + expected_exit_code=128 + ansible-lint || exit_code=$? + if [ "$exit_code" != "$expected_exit_code" ]; then echo "Command failed: got '$exit_code', expected '$expected_exit_code'"; exit 1; fi molecule: name: Molecule From 40542b4f65d1ec8b184d6f5dccd37245fd24cd87 Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:50:45 +0400 Subject: [PATCH 09/11] fix: lint --- .yamllint | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.yamllint b/.yamllint index ea2b819..2a1bd31 100644 --- a/.yamllint +++ b/.yamllint @@ -5,6 +5,7 @@ rules: line-length: max: 200 level: warning + comments-indentation: false comments: # prettier compatibility min-spaces-from-content: 1 @@ -16,6 +17,8 @@ rules: octal-values: forbid-implicit-octal: true forbid-explicit-octal: true + braces: + max-spaces-inside: 1 ignore: | .github/stale.yml From 3aea2293c761af2b599a3dbc3b35b573df538813 Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 01:52:40 +0400 Subject: [PATCH 10/11] fix: expected_exit_code --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8bb92e1..afd700d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: - name: Run ansible-lint run: | exit_code=0 - expected_exit_code=128 + expected_exit_code=0 ansible-lint || exit_code=$? if [ "$exit_code" != "$expected_exit_code" ]; then echo "Command failed: got '$exit_code', expected '$expected_exit_code'"; exit 1; fi From 1af673ae480aa30b0bd853222ae003965bce8eed Mon Sep 17 00:00:00 2001 From: bulch Date: Wed, 18 Dec 2024 02:15:24 +0400 Subject: [PATCH 11/11] fix: verify --- molecule/default/converge.yml | 2 +- molecule/default/molecule.yml | 2 ++ molecule/default/verify.yml | 17 ++++++++++++++--- .../testrsync_server/defaults/main.yml | 0 .../testrsync_server/tasks/main.yml | 6 +++--- 5 files changed, 20 insertions(+), 7 deletions(-) rename {tests => roles}/testrsync_server/defaults/main.yml (100%) rename {tests => roles}/testrsync_server/tasks/main.yml (93%) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index c6a85ca..056575d 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -39,7 +39,7 @@ tasks: - name: Include bulch.rsync_server ansible.legacy.include_role: - name: "bulch.rsync_server" + name: bulch.rsync_server - name: Check uname ansible.builtin.raw: uname -a diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 4863dff..dc4727c 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -33,6 +33,8 @@ provisioner: verifier: name: ansible + env: + ANSIBLE_ROLES_PATH: "../../roles" lint: | diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 08f01e8..3ca5bba 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,10 +1,21 @@ --- -# This is an example playbook to execute Ansible tests. +- name: Fail if molecule group is missing + hosts: localhost + tasks: + - name: Print some info + ansible.builtin.debug: + msg: "{{ groups }}" + + - name: Assert group existence + ansible.builtin.assert: + that: "'molecule' in groups" + fail_msg: | + molecule group was not found inside inventory groups: {{ groups }} - name: Verify - hosts: all + hosts: molecule gather_facts: false tasks: - name: Include test-rsync_server ansible.legacy.include_role: - name: "test-rsync_server" + name: testrsync_server diff --git a/tests/testrsync_server/defaults/main.yml b/roles/testrsync_server/defaults/main.yml similarity index 100% rename from tests/testrsync_server/defaults/main.yml rename to roles/testrsync_server/defaults/main.yml diff --git a/tests/testrsync_server/tasks/main.yml b/roles/testrsync_server/tasks/main.yml similarity index 93% rename from tests/testrsync_server/tasks/main.yml rename to roles/testrsync_server/tasks/main.yml index 9561de3..ebcf4f8 100644 --- a/tests/testrsync_server/tasks/main.yml +++ b/roles/testrsync_server/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: Test retrieve information from path ansible.builtin.stat: - path: "{{ path_default_config_rsync }}" + path: "{{ testrsync_server_path_default_config_rsync }}" register: default_config - name: Test assert that file rsync config is created correctly @@ -14,7 +14,7 @@ - name: Test retrieve information from path secret_rsync config ansible.builtin.stat: - path: "{{ path_secret_rsync }}" + path: "{{ testrsync_server_path_secret_rsync }}" register: secret_rsync - name: Test assert that file secret_rsync is created correctly @@ -27,7 +27,7 @@ - name: Test rsync_config retrieve information from path ansible.builtin.stat: - path: "{{ path_rsync_config }}" + path: "{{ testrsync_server_path_rsync_config }}" register: secret_rsync - name: Test assert that file rsync_config is created correctly