From f186728903b5bd09ec639a7df3f99ecdfadb478d Mon Sep 17 00:00:00 2001
From: fejao <mail@fejao.de>
Date: Fri, 31 Jan 2025 15:11:17 +0100
Subject: [PATCH] Updated the molecule tests for the 'test' role.

---
 ansible.cfg                                   | 48 +++++++--------
 .../examples/example_04_docker_images.yml     |  2 +-
 roles/dependencies/tasks/install_packages.yml |  1 +
 .../group_vars/example_servers_group.yml      |  2 -
 .../inventory/host_vars/example_server.yml    |  2 -
 roles/test/molecule/default/molecule.yml      | 57 +++++++++++++-----
 .../molecule/default/tests/test_default.yml   | 34 -----------
 roles/test/molecule/default/verify.yml        | 59 +++++++++++++++++++
 8 files changed, 128 insertions(+), 77 deletions(-)
 delete mode 100644 roles/test/molecule/default/inventory/group_vars/example_servers_group.yml
 delete mode 100644 roles/test/molecule/default/inventory/host_vars/example_server.yml
 delete mode 100644 roles/test/molecule/default/tests/test_default.yml
 create mode 100644 roles/test/molecule/default/verify.yml

diff --git a/ansible.cfg b/ansible.cfg
index 873a8ba..026fed0 100644
--- a/ansible.cfg
+++ b/ansible.cfg
@@ -32,7 +32,7 @@
 ;become_password_file=
 
 # (pathspec) Colon-separated paths in which Ansible will search for Become Plugins.
-;become_plugins=/home/fejao/.ansible/plugins/become:/usr/share/ansible/plugins/become
+;become_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/become:/usr/share/ansible/plugins/become
 
 # (string) Chooses which cache plugin to use, the default 'memory' is ephemeral.
 ;fact_caching=memory
@@ -54,7 +54,7 @@
 
 # (pathspec) Colon-separated paths in which Ansible will search for collections content. Collections must be in nested *subdirectories*, not directly in these directories. For example, if ``COLLECTIONS_PATHS`` includes ``'{{ ANSIBLE_HOME ~ "/collections" }}'``, and you want to add ``my.collection`` to that directory, it must be saved as ``'{{ ANSIBLE_HOME} ~ "/collections/ansible_collections/my/collection" }}'``.
 
-;collections_path=/home/fejao/.ansible/collections:/usr/share/ansible/collections
+;collections_path=/home/<YOUR_USER_NAME>/.ansible/collections:/usr/share/ansible/collections
 
 # (boolean) A boolean to enable or disable scanning the sys.path for installed collections.
 ;collections_scan_sys_path=True
@@ -63,7 +63,7 @@
 ;connection_password_file=
 
 # (pathspec) Colon-separated paths in which Ansible will search for Action Plugins.
-;action_plugins=/home/fejao/.ansible/plugins/action:/usr/share/ansible/plugins/action
+;action_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/action:/usr/share/ansible/plugins/action
 
 # (boolean) When enabled, this option allows lookup plugins (whether used in variables as ``{{lookup('foo')}}`` or as a loop as with_foo) to return data that is not marked 'unsafe'.
 # By default, such data is marked as unsafe to prevent the templating engine from evaluating any jinja2 templating language, as this could represent a security risk. This option is provided to allow for backward compatibility, however, users should first consider adding allow_unsafe=True to any lookups that may be expected to contain data that may be run through the templating engine late.
@@ -76,16 +76,16 @@
 ;ask_vault_pass=False
 
 # (pathspec) Colon-separated paths in which Ansible will search for Cache Plugins.
-;cache_plugins=/home/fejao/.ansible/plugins/cache:/usr/share/ansible/plugins/cache
+;cache_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/cache:/usr/share/ansible/plugins/cache
 
 # (pathspec) Colon-separated paths in which Ansible will search for Callback Plugins.
-;callback_plugins=/home/fejao/.ansible/plugins/callback:/usr/share/ansible/plugins/callback
+;callback_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/callback:/usr/share/ansible/plugins/callback
 
 # (pathspec) Colon-separated paths in which Ansible will search for Cliconf Plugins.
-;cliconf_plugins=/home/fejao/.ansible/plugins/cliconf:/usr/share/ansible/plugins/cliconf
+;cliconf_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/cliconf:/usr/share/ansible/plugins/cliconf
 
 # (pathspec) Colon-separated paths in which Ansible will search for Connection Plugins.
-;connection_plugins=/home/fejao/.ansible/plugins/connection:/usr/share/ansible/plugins/connection
+;connection_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/connection:/usr/share/ansible/plugins/connection
 
 # (boolean) Toggles debug output in Ansible. This is *very* verbose and can hinder multiprocessing. Debug output can also include secret information despite no_log settings being enabled, which means debug mode should not be used in production.
 ;debug=False
@@ -100,7 +100,7 @@
 ;fact_path=
 
 # (pathspec) Colon-separated paths in which Ansible will search for Jinja2 Filter Plugins.
-;filter_plugins=/home/fejao/.ansible/plugins/filter:/usr/share/ansible/plugins/filter
+;filter_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/filter:/usr/share/ansible/plugins/filter
 
 # (boolean) This option controls if notified handlers run on a host even if a failure occurs on that host.
 # When false, the handlers will not run if a failure has occurred on a host.
@@ -140,14 +140,14 @@ inventory=$PWD/inventories/hosts
 # inventory=$PWD/inventory
 
 # (pathspec) Colon-separated paths in which Ansible will search for HttpApi Plugins.
-;httpapi_plugins=/home/fejao/.ansible/plugins/httpapi:/usr/share/ansible/plugins/httpapi
+;httpapi_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/httpapi:/usr/share/ansible/plugins/httpapi
 
 # (float) This sets the interval (in seconds) of Ansible internal processes polling each other. Lower values improve performance with large playbooks at the expense of extra CPU load. Higher values are more suitable for Ansible usage in automation scenarios when UI responsiveness is not required but CPU usage might be a concern.
 # The default corresponds to the value hardcoded in Ansible <= 2.1
 ;internal_poll_interval=0.001
 
 # (pathspec) Colon-separated paths in which Ansible will search for Inventory Plugins.
-;inventory_plugins=/home/fejao/.ansible/plugins/inventory:/usr/share/ansible/plugins/inventory
+;inventory_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/inventory:/usr/share/ansible/plugins/inventory
 
 # (string) This is a developer-specific feature that allows enabling additional Jinja2 extensions.
 # See the Jinja2 documentation for details. If you do not know what these do, you probably don't need to change this setting :)
@@ -164,7 +164,7 @@ inventory=$PWD/inventories/hosts
 ;bin_ansible_callbacks=False
 
 # (tmppath) Temporary directory for Ansible to use on the controller.
-;local_tmp=/home/fejao/.ansible/tmp
+;local_tmp=/home/<YOUR_USER_NAME>/.ansible/tmp
 
 # (list) List of logger names to filter out of the log file.
 ;log_filter=
@@ -173,7 +173,7 @@ inventory=$PWD/inventories/hosts
 ;log_path=
 
 # (pathspec) Colon-separated paths in which Ansible will search for Lookup Plugins.
-;lookup_plugins=/home/fejao/.ansible/plugins/lookup:/usr/share/ansible/plugins/lookup
+;lookup_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/lookup:/usr/share/ansible/plugins/lookup
 
 # (string) Sets the macro for the 'ansible_managed' variable available for :ref:`ansible_collections.ansible.builtin.template_module` and :ref:`ansible_collections.ansible.windows.win_template_module`.  This is only relevant to those two modules.
 ;ansible_managed=Ansible managed
@@ -188,13 +188,13 @@ inventory=$PWD/inventories/hosts
 ;module_name=command
 
 # (pathspec) Colon-separated paths in which Ansible will search for Modules.
-;library=/home/fejao/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
+;library=/home/<YOUR_USER_NAME>/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
 
 # (pathspec) Colon-separated paths in which Ansible will search for Module utils files, which are shared by modules.
-;module_utils=/home/fejao/.ansible/plugins/module_utils:/usr/share/ansible/plugins/module_utils
+;module_utils=/home/<YOUR_USER_NAME>/.ansible/plugins/module_utils:/usr/share/ansible/plugins/module_utils
 
 # (pathspec) Colon-separated paths in which Ansible will search for Netconf Plugins.
-;netconf_plugins=/home/fejao/.ansible/plugins/netconf:/usr/share/ansible/plugins/netconf
+;netconf_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/netconf:/usr/share/ansible/plugins/netconf
 
 # (boolean) Toggle Ansible's display and logging of task details, mainly used to avoid security disclosures.
 ;no_log=False
@@ -227,7 +227,7 @@ inventory=$PWD/inventories/hosts
 remote_user=test-user
 
 # (pathspec) Colon-separated paths in which Ansible will search for Roles.
-;roles_path=/home/fejao/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
+;roles_path=/home/<YOUR_USER_NAME>/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
 
 # (string) Set the main callback used to display Ansible output. You can only have one at a time.
 # You can have many other callbacks, but just one can be in charge of stdout.
@@ -238,7 +238,7 @@ remote_user=test-user
 ;strategy=linear
 
 # (pathspec) Colon-separated paths in which Ansible will search for Strategy Plugins.
-;strategy_plugins=/home/fejao/.ansible/plugins/strategy:/usr/share/ansible/plugins/strategy
+;strategy_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/strategy:/usr/share/ansible/plugins/strategy
 
 # (boolean) Toggle the use of "su" for tasks.
 ;su=False
@@ -247,10 +247,10 @@ remote_user=test-user
 ;syslog_facility=LOG_USER
 
 # (pathspec) Colon-separated paths in which Ansible will search for Terminal Plugins.
-;terminal_plugins=/home/fejao/.ansible/plugins/terminal:/usr/share/ansible/plugins/terminal
+;terminal_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/terminal:/usr/share/ansible/plugins/terminal
 
 # (pathspec) Colon-separated paths in which Ansible will search for Jinja2 Test Plugins.
-;test_plugins=/home/fejao/.ansible/plugins/test:/usr/share/ansible/plugins/test
+;test_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/test:/usr/share/ansible/plugins/test
 
 # (integer) This is the default timeout for connection plugins to use.
 ;timeout=10
@@ -264,7 +264,7 @@ remote_user=test-user
 ;error_on_undefined_vars=True
 
 # (pathspec) Colon-separated paths in which Ansible will search for Vars Plugins.
-;vars_plugins=/home/fejao/.ansible/plugins/vars:/usr/share/ansible/plugins/vars
+;vars_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/vars:/usr/share/ansible/plugins/vars
 
 # (string) The vault_id to use for encrypting by default. If multiple vault_ids are provided, this specifies which to use for encryption. The ``--encrypt-vault-id`` CLI option overrides the configured value.
 ;vault_encrypt_identity=
@@ -305,7 +305,7 @@ deprecation_warnings=False
 ;docsite_root_url=https://docs.ansible.com/ansible-core/
 
 # (pathspec) Colon-separated paths in which Ansible will search for Documentation Fragments Plugins.
-;doc_fragment_plugins=/home/fejao/.ansible/plugins/doc_fragments:/usr/share/ansible/plugins/doc_fragments
+;doc_fragment_plugins=/home/<YOUR_USER_NAME>/.ansible/plugins/doc_fragments:/usr/share/ansible/plugins/doc_fragments
 
 # (string) By default, Ansible will issue a warning when a duplicate dict key is encountered in YAML.
 # These warnings can be silenced by adjusting this setting to False.
@@ -533,7 +533,7 @@ interpreter_python=auto_silent
 ;connect_timeout=30
 
 # (path) Path to the socket to be used by the connection persistence system.
-;control_path_dir=/home/fejao/.ansible/pc
+;control_path_dir=/home/<YOUR_USER_NAME>/.ansible/pc
 
 
 [connection]
@@ -610,7 +610,7 @@ interpreter_python=auto_silent
 # (path) The directory that stores cached responses from a Galaxy server.
 # This is only used by the ``ansible-galaxy collection install`` and ``download`` commands.
 # Cache files inside this dir will be ignored if they are world writable.
-;cache_dir=/home/fejao/.ansible/galaxy_cache
+;cache_dir=/home/<YOUR_USER_NAME>/.ansible/galaxy_cache
 
 # (bool) whether ``ansible-galaxy collection install`` should warn about ``--collections-path`` missing from configured :ref:`collections_paths`.
 ;collections_path_warning=True
@@ -664,7 +664,7 @@ interpreter_python=auto_silent
 ;server_timeout=60
 
 # (path) Local path to galaxy access token file
-;token_path=/home/fejao/.ansible/galaxy_token
+;token_path=/home/<YOUR_USER_NAME>/.ansible/galaxy_token
 
 
 [inventory]
diff --git a/playbooks/examples/example_04_docker_images.yml b/playbooks/examples/example_04_docker_images.yml
index 154d3d3..a3ad2dd 100644
--- a/playbooks/examples/example_04_docker_images.yml
+++ b/playbooks/examples/example_04_docker_images.yml
@@ -5,4 +5,4 @@
   hosts:
     - example_servers_group
   roles:
-    - docker_images
+    - roles/docker_images
diff --git a/roles/dependencies/tasks/install_packages.yml b/roles/dependencies/tasks/install_packages.yml
index 46ff39a..5e7390f 100644
--- a/roles/dependencies/tasks/install_packages.yml
+++ b/roles/dependencies/tasks/install_packages.yml
@@ -4,6 +4,7 @@
   ansible.builtin.package:
     name: "{{ package_name }}"
     state: present
+    update_cache: true
   loop: "{{ os_dependencies_packages }}"
   loop_control:
     loop_var: package_name
diff --git a/roles/test/molecule/default/inventory/group_vars/example_servers_group.yml b/roles/test/molecule/default/inventory/group_vars/example_servers_group.yml
deleted file mode 100644
index 7ba656a..0000000
--- a/roles/test/molecule/default/inventory/group_vars/example_servers_group.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-var_setted_only_group_vars: "group_vars_value"
-var_setted_everywhere: "group_vars_value"
diff --git a/roles/test/molecule/default/inventory/host_vars/example_server.yml b/roles/test/molecule/default/inventory/host_vars/example_server.yml
deleted file mode 100644
index 3ed6bf4..0000000
--- a/roles/test/molecule/default/inventory/host_vars/example_server.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-var_setted_only_host_vars: "host_vars_value"
-var_setted_everywhere: "host_vars_value"
diff --git a/roles/test/molecule/default/molecule.yml b/roles/test/molecule/default/molecule.yml
index 55eb160..7b5a4dc 100644
--- a/roles/test/molecule/default/molecule.yml
+++ b/roles/test/molecule/default/molecule.yml
@@ -10,9 +10,10 @@ platforms:
     pre_build_image: true
 provisioner:
   name: ansible
-  lint:
-    name: ansible-lint
   inventory:
+    ###
+    ### VARS used from the role
+    ###
     group_vars:
       example_servers_group:
         var_setted_only_group_vars: "group_vars_value"
@@ -21,17 +22,45 @@ provisioner:
       instance:
         var_setted_only_host_vars: "host_vars_value"
         var_setted_everywhere: "host_vars_value"
+lint: |
+  ansible-lint --exclude molecule/default/
+scenario:
+  name: default
+  create_sequence:
+    - dependency
+    - create
+    - prepare
+  check_sequence:
+    - dependency
+    - cleanup
+    - destroy
+    - create
+    - prepare
+    - converge
+    - check
+    - destroy
+  converge_sequence:
+    - dependency
+    - create
+    - prepare
+    - converge
+  destroy_sequence:
+    - dependency
+    - cleanup
+    - destroy
+  test_sequence:
+    # - lint
+    # - dependency
+    # - cleanup
+    - destroy
+    - syntax
+    - create
+    # - prepare
+    - converge
+    - verify
+    - idempotence
+    # - side_effect
+    # - cleanup
+    - destroy
 verifier:
   name: ansible
-  ###
-  # lint:
-  #   name: ansible-lint
-  ###
-  # playbook: verify.yml
-  ###
-  # Remove the 'playbooks' key and use 'playbooks' directly under 'verifier'
-  # playbooks:
-  #   verify: verify.yml
-  ###
-  # lint:
-  #   name: flake8
diff --git a/roles/test/molecule/default/tests/test_default.yml b/roles/test/molecule/default/tests/test_default.yml
deleted file mode 100644
index 75dae12..0000000
--- a/roles/test/molecule/default/tests/test_default.yml
+++ /dev/null
@@ -1,34 +0,0 @@
----
-- name: MOLECULE | Test role for debugging variables
-  hosts: all
-  tasks:
-    - name: MOLECULE | TESTS | Test parsed variable setted only at roles/test/defaults/main.yml
-      ansible.builtin.debug:
-        msg: "{{ var_setted_only_defaults_main }}"
-
-    - name: MOLECULE | TESTS | Test parsed variable setted only at roles/test/vars/main.yml
-      ansible.builtin.debug:
-        msg: "{{ var_setted_only_vars_main }}"
-
-    - name: MOLECULE | TESTS | Test parsed variable setted only at inventory/group_vars/example_servers_group.yml
-      ansible.builtin.debug:
-        msg: "{{ var_setted_only_group_vars }}"
-      when: var_setted_only_group_vars is defined
-
-    - name: MOLECULE | TESTS | Test parsed variable setted only at inventory/host_vars/example_server.yml
-      ansible.builtin.debug:
-        msg: "{{ var_setted_only_host_vars }}"
-
-    - name: MOLECULE | TESTS | Test parsed variable setted EVERYWHERE -> should come from roles/test/vars/main.yml
-      ansible.builtin.debug:
-        msg: "{{ var_setted_everywhere }}"
-
-    - name: MOLECULE | TESTS | List the root ('/') folder from the target to a register
-      ansible.builtin.command:
-        cmd: ls -hal /
-      register: ret_list_folder
-      changed_when: false
-
-    - name: MOLECULE | TESTS | Shows output from listing folder
-      ansible.builtin.debug:
-        msg: "{{ ret_list_folder }}"
diff --git a/roles/test/molecule/default/verify.yml b/roles/test/molecule/default/verify.yml
new file mode 100644
index 0000000..5dd983f
--- /dev/null
+++ b/roles/test/molecule/default/verify.yml
@@ -0,0 +1,59 @@
+---
+- name: VERIFY | Test role for debugging variables
+  hosts: all
+  pre_tasks:
+    - name: MOLECULE | VERIFY | PRE-TASKS | Adding variables from -> ../../../../inventories/group_vars
+      ansible.builtin.include_vars:
+        dir: ../../../../inventories/group_vars
+        extensions:
+          - 'yml'
+
+    - name: MOLECULE | VERIFY | PRE-TASKS | Adding variables from -> ../../../../inventories/host_vars
+      ansible.builtin.include_vars:
+        dir: ../../../../inventories/host_vars
+        extensions:
+          - 'yml'
+
+    - name: MOLECULE | VERIFY | PRE-TASKS | Adding variables from -> ../../defaults
+      ansible.builtin.include_vars:
+        dir: ../../defaults
+        extensions:
+          - 'yml'
+
+    - name: MOLECULE | VERIFY | PRE-TASKS | Adding variables from -> ../../vars
+      ansible.builtin.include_vars:
+        dir: ../../vars
+        extensions:
+          - 'yml'
+
+  tasks:
+    - name: MOLECULE | VERIFY | Test parsed variable setted only at roles/test/defaults/main.yml
+      ansible.builtin.debug:
+        msg: "{{ var_setted_only_defaults_main }}"
+
+    - name: MOLECULE | VERIFY | Test parsed variable setted only at roles/test/vars/main.yml
+      ansible.builtin.debug:
+        msg: "{{ var_setted_only_vars_main }}"
+
+    - name: MOLECULE | VERIFY | Test parsed variable setted only at inventory/group_vars/example_servers_group.yml
+      ansible.builtin.debug:
+        msg: "{{ var_setted_only_group_vars }}"
+      when: var_setted_only_group_vars is defined
+
+    - name: MOLECULE | VERIFY | Test parsed variable setted only at inventory/host_vars/example_server.yml
+      ansible.builtin.debug:
+        msg: "{{ var_setted_only_host_vars }}"
+
+    - name: MOLECULE | VERIFY | Test parsed variable setted EVERYWHERE -> should come from roles/test/vars/main.yml
+      ansible.builtin.debug:
+        msg: "{{ var_setted_everywhere }}"
+
+    - name: MOLECULE | VERIFY | List the root ('/') folder from the target to a register
+      ansible.builtin.command:
+        cmd: ls -hal /
+      register: ret_list_folder
+      changed_when: false
+
+    - name: MOLECULE | VERIFY | Shows output from listing folder
+      ansible.builtin.debug:
+        msg: "{{ ret_list_folder }}"
-- 
GitLab