From 8eb8c69c4916c8d78b740df8f1573f6229cc4f3d Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Tue, 23 May 2023 22:20:19 +0200 Subject: [PATCH] started doing tests in ansible since testinfra is being deprecated --- defaults/main.yml | 4 +-- molecule/with_custom_ca/converge.yml | 7 ++++ molecule/with_custom_ca/group_vars/all.yml | 4 +++ molecule/with_custom_ca/molecule.yml | 37 ++++++++++++++++++++++ molecule/with_custom_ca/requirements.yml | 3 ++ molecule/with_custom_ca/verify.yml | 24 ++++++++++++++ 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 molecule/with_custom_ca/converge.yml create mode 100644 molecule/with_custom_ca/group_vars/all.yml create mode 100644 molecule/with_custom_ca/molecule.yml create mode 100644 molecule/with_custom_ca/requirements.yml create mode 100644 molecule/with_custom_ca/verify.yml diff --git a/defaults/main.yml b/defaults/main.yml index 861dc85..57588de 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,3 @@ --- # defaults file for import_vault_root_ca -import_vault_root_ca_certificate_list: - - url: "https://openstack01.ednz.fr:8200/v1/ednz-root-ca/ca" - cert_name: "ednz_ca" +import_vault_root_ca_certificate_list: {} diff --git a/molecule/with_custom_ca/converge.yml b/molecule/with_custom_ca/converge.yml new file mode 100644 index 0000000..a49f5c4 --- /dev/null +++ b/molecule/with_custom_ca/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include ednxzu.import_vault_root_ca" + ansible.builtin.include_role: + name: "ednxzu.import_vault_root_ca" diff --git a/molecule/with_custom_ca/group_vars/all.yml b/molecule/with_custom_ca/group_vars/all.yml new file mode 100644 index 0000000..6ff14db --- /dev/null +++ b/molecule/with_custom_ca/group_vars/all.yml @@ -0,0 +1,4 @@ +--- +import_vault_root_ca_certificate_list: + - url: "https://openstack01.ednz.fr:8200/v1/ednz-root-ca/ca" + cert_name: "ednz_ca" \ No newline at end of file diff --git a/molecule/with_custom_ca/molecule.yml b/molecule/with_custom_ca/molecule.yml new file mode 100644 index 0000000..7150297 --- /dev/null +++ b/molecule/with_custom_ca/molecule.yml @@ -0,0 +1,37 @@ +--- +dependency: + name: galaxy + options: + requirements-file: ./requirements.yml +driver: + name: docker +platforms: + - name: instance + image: geerlingguy/docker-${MOLECULE_TEST_OS}-ansible + command: "" + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup + cgroupns_mode: host + privileged: true + pre_build_image: true +provisioner: + name: ansible + config_options: + defaults: + remote_tmp: /tmp/.ansible +verifier: + name: ansible +scenario: + name: with_custom_ca + test_sequence: + - dependency + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - idempotence + - verify + - cleanup + - destroy diff --git a/molecule/with_custom_ca/requirements.yml b/molecule/with_custom_ca/requirements.yml new file mode 100644 index 0000000..e9320f9 --- /dev/null +++ b/molecule/with_custom_ca/requirements.yml @@ -0,0 +1,3 @@ +--- +# requirements file for molecule +roles: [] diff --git a/molecule/with_custom_ca/verify.yml b/molecule/with_custom_ca/verify.yml new file mode 100644 index 0000000..ee4599b --- /dev/null +++ b/molecule/with_custom_ca/verify.yml @@ -0,0 +1,24 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: "Test: directory /usr/local/share/ca-certificates" + block: + - name: "Stat directory /usr/local/share/ca-certificates" + ansible.builtin.stat: + path: "/usr/local/share/ca-certificates" + register: usr_local_share_ca_certificates + + - name: "Verify directory {{ import_vault_root_ca_cert_dir }}" + ansible.builtin.assert: + that: + - usr_local_share_ca_certificates.stat.exists + - usr_local_share_ca_certificates.stat.isdir + - usr_local_share_ca_certificates.stat.pw_name == 'root' + - usr_local_share_ca_certificates.stat.gr_name == 'root' + - usr_local_share_ca_certificates.stat.mode == '0755' + + - name: "Get certificate information"