From e1a216a90e3dc9fa98187509d7cf507f7a31774d Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Thu, 20 Jul 2023 23:53:09 +0200 Subject: [PATCH] added ansible tesT --- .gitea/workflows/test.yml | 52 +++++++++++++++++++ molecule/default/molecule.yml | 2 +- molecule/default/verify.yml | 25 ++++++++- molecule/with_custom_ascii/group_vars/all.yml | 2 +- molecule/with_custom_ascii/molecule.yml | 2 +- molecule/with_custom_ascii/verify.yml | 25 ++++++++- 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 .gitea/workflows/test.yml diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..f1fc703 --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,52 @@ +--- +name: test +on: [push] + +jobs: + lint: + name: Linting + runs-on: ubuntu-latest + container: + image: git.ednz.fr/container-factory/ansible-runner:act-latest + credentials: + username: ${{ secrets.ACTIONS_USER }} + password: ${{ secrets.ACTIONS_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: "Ansible lint" + run: ansible-lint --force-color + working-directory: ${{ gitea.workspace }} + + - name: "YAML lint" + run: yamllint . -f colored -c .yamllint + working-directory: ${{ gitea.workspace }} + + molecule-test: + name: Molecule tests + runs-on: ubuntu-latest + needs: lint + container: + image: git.ednz.fr/container-factory/ansible-runner:act-latest + credentials: + username: ${{ secrets.ACTIONS_USER }} + password: ${{ secrets.ACTIONS_TOKEN }} + strategy: + matrix: + test_os: [debian11, debian12, ubuntu2004, ubuntu2204] + scenario: [default, with_custom_ascii] + env: + ANSIBLE_HOST_KEY_CHECKING: 'false' + ANSIBLE_FORCE_COLOR: 'true' + ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: "Molecule test" + run: molecule test -s ${{ matrix.scenario }} + shell: bash + working-directory: ${{ gitea.workspace }} + env: + MOLECULE_TEST_OS: ${{ matrix.test_os }} diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 7a62eb2..49efc7f 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -20,7 +20,7 @@ provisioner: defaults: remote_tmp: /tmp/.ansible verifier: - name: testinfra + name: ansible scenario: name: default test_sequence: diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index bf52da2..5c674dc 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,7 +1,7 @@ --- - name: Verify hosts: all - gather_facts: false + gather_facts: true tasks: - name: "Test: file /etc/hosts" block: @@ -17,3 +17,26 @@ - stat_etc_hosts.stat.isreg - stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.gr_name == 'root' + + - name: "Test: file /etc/profile.d/motd.cfg" + block: + - name: "Stat file /etc/profile.d/motd.cfg" + ansible.builtin.stat: + path: "/etc/profile.d/motd.cfg" + register: stat_etc_profile_d_motd_cfg + + - name: "Slurp file /etc/profile.d/motd.cfg" + ansible.builtin.slurp: + src: "/etc/profile.d/motd.cfg" + register: slurp_etc_profile_d_motd_cfg + + - name: "Verify file /etc/profile.d/motd.cfg" + ansible.builtin.assert: + that: + - stat_etc_profile_d_motd_cfg.stat.exists + - stat_etc_profile_d_motd_cfg.stat.isreg + - stat_etc_profile_d_motd_cfg.stat.pw_name == 'root' + - stat_etc_profile_d_motd_cfg.stat.gr_name == 'root' + - stat_etc_profile_d_motd_cfg.stat.mode == '0644' + - "'print_info()' in (slurp_etc_profile_d_motd_cfg.content|b64decode)" + - "'ascii_distro=\"auto\"' in (slurp_etc_profile_d_motd_cfg.content|b64decode)" diff --git a/molecule/with_custom_ascii/group_vars/all.yml b/molecule/with_custom_ascii/group_vars/all.yml index 3038409..2f8d634 100644 --- a/molecule/with_custom_ascii/group_vars/all.yml +++ b/molecule/with_custom_ascii/group_vars/all.yml @@ -9,4 +9,4 @@ update_motd_print_info: module: local_ip - name: "Disk" module: "disk" -update_motd_ascii_distro: "{{ ansible_distribution }}_small" +update_motd_ascii_distro: "{{ ansible_distribution|lower }}_small" diff --git a/molecule/with_custom_ascii/molecule.yml b/molecule/with_custom_ascii/molecule.yml index 04bb465..114f2ff 100644 --- a/molecule/with_custom_ascii/molecule.yml +++ b/molecule/with_custom_ascii/molecule.yml @@ -20,7 +20,7 @@ provisioner: defaults: remote_tmp: /tmp/.ansible verifier: - name: testinfra + name: ansible scenario: name: with_custom_ascii test_sequence: diff --git a/molecule/with_custom_ascii/verify.yml b/molecule/with_custom_ascii/verify.yml index bf52da2..ea405fc 100644 --- a/molecule/with_custom_ascii/verify.yml +++ b/molecule/with_custom_ascii/verify.yml @@ -1,7 +1,7 @@ --- - name: Verify hosts: all - gather_facts: false + gather_facts: true tasks: - name: "Test: file /etc/hosts" block: @@ -17,3 +17,26 @@ - stat_etc_hosts.stat.isreg - stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.gr_name == 'root' + + - name: "Test: file /etc/profile.d/motd.cfg" + block: + - name: "Stat file /etc/profile.d/motd.cfg" + ansible.builtin.stat: + path: "/etc/profile.d/motd.cfg" + register: stat_etc_profile_d_motd_cfg + + - name: "Slurp file /etc/profile.d/motd.cfg" + ansible.builtin.slurp: + src: "/etc/profile.d/motd.cfg" + register: slurp_etc_profile_d_motd_cfg + + - name: "Verify file /etc/profile.d/motd.cfg" + ansible.builtin.assert: + that: + - stat_etc_profile_d_motd_cfg.stat.exists + - stat_etc_profile_d_motd_cfg.stat.isreg + - stat_etc_profile_d_motd_cfg.stat.pw_name == 'root' + - stat_etc_profile_d_motd_cfg.stat.gr_name == 'root' + - stat_etc_profile_d_motd_cfg.stat.mode == '0644' + - "'print_info()' in (slurp_etc_profile_d_motd_cfg.content|b64decode)" + - "'ascii_distro=\"{{ ansible_distribution|lower|string }}_small\"' in (slurp_etc_profile_d_motd_cfg.content|b64decode)"