diff --git a/.config/requirements-docs.txt b/.config/requirements-docs.txt index 5f4bbb5aa6..884fe492ef 100644 --- a/.config/requirements-docs.txt +++ b/.config/requirements-docs.txt @@ -1,3 +1,3 @@ mkdocs-ansible[lock]>=0.1.4 pipdeptree>=2.4.0 -linkchecker +linkchecker==10.2.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3249db9af1..2a7f7fdeb5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/mirrors-prettier # keep it before yamllint - rev: "v3.0.2" + rev: "v3.0.3" hooks: - id: prettier # Temporary excludes so we can gradually normalize the formatting @@ -16,16 +16,16 @@ repos: - prettier - prettier-plugin-toml - repo: https://github.com/codespell-project/codespell - rev: v2.2.5 + rev: v2.2.6 hooks: - id: codespell - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.9.1 hooks: - id: black language_version: python3 - repo: https://github.com/pre-commit/pre-commit-hooks.git - rev: v4.4.0 + rev: v4.5.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace @@ -44,12 +44,12 @@ repos: types: [file, yaml] entry: yamllint --strict - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.0.285" + rev: "v0.0.292" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.6.0 hooks: - id: mypy # empty args needed in order to match mypy cli behavior @@ -74,7 +74,7 @@ repos: - types-setuptools - wcmatch - repo: https://github.com/pycqa/pylint - rev: v3.0.0a7 + rev: v3.0.1 hooks: - id: pylint args: diff --git a/docs/examples.md b/docs/examples.md index ffdccb64c2..030c248691 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -39,7 +39,7 @@ scenario's generated `molecule.yml` file. ## Docker With Non-Privileged User -The default Molecule Docker driver executes Ansible playbooks as the +The Molecule Docker driver executes Ansible playbooks as the root user. If your workflow requires adding support for running as a non-privileged user, then adapt `molecule.yml` and `Dockerfile.j2` as follows. diff --git a/docs/getting-started.md b/docs/getting-started.md index 9915cc9f0e..09948334bf 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -118,8 +118,8 @@ components that Molecule provides. These are: uses [galaxy development guide] by default to resolve your role dependencies. - The [driver](configuration.md#driver) provider. Molecule uses - [Docker](https://docs.docker.com/) by default. Molecule uses the - driver to delegate the task of creating instances. + the [Delegated](configuration.md#delegated) driver by default. + Molecule uses the driver to delegate the task of creating instances. - The [platforms](configuration.md#platforms) definitions. Molecule relies on this to know which instances to create, name and to which group each instance belongs. If you need to test your role against diff --git a/molecule/default/create.yml b/molecule/default/create.yml index b33ceb6c82..c847720b32 100644 --- a/molecule/default/create.yml +++ b/molecule/default/create.yml @@ -34,4 +34,4 @@ {{ instance_conf | to_json | from_json | to_yaml }} dest: "{{ molecule_instance_config }}" - mode: 0600 + mode: "0600" diff --git a/molecule/default/destroy.yml b/molecule/default/destroy.yml index f4493abea5..37137c3de2 100644 --- a/molecule/default/destroy.yml +++ b/molecule/default/destroy.yml @@ -20,5 +20,5 @@ {{ instance_conf | to_json | from_json | to_yaml }} dest: "{{ molecule_instance_config }}" - mode: 0600 + mode: "0600" when: server.changed | default(false) | bool # noqa no-handler diff --git a/molecule/docker/create.yml b/molecule/docker/create.yml index f2b363b69a..1b028745fd 100644 --- a/molecule/docker/create.yml +++ b/molecule/docker/create.yml @@ -42,7 +42,7 @@ ansible_connection: community.docker.docker ansible.builtin.set_fact: molecule_inventory: > - {{ molecule_inventory | combine(inventory_partial_yaml | from_yaml) }} + {{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }} loop: "{{ molecule_yml.platforms }}" loop_control: label: "{{ item.name }}" @@ -52,7 +52,7 @@ content: | {{ molecule_inventory | to_yaml }} dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml" - mode: 0600 + mode: "0600" - name: Force inventory refresh ansible.builtin.meta: refresh_inventory diff --git a/molecule/kubevirt/create.yml b/molecule/kubevirt/create.yml index f53c389db3..3f92133d6d 100644 --- a/molecule/kubevirt/create.yml +++ b/molecule/kubevirt/create.yml @@ -6,7 +6,7 @@ temporary_ssh_key_size: 2048 # Variable for the size of the SSH key tasks: - name: Set default SSH key path # Sets the path of the SSH key - set_fact: + ansible.builtin.set_fact: tempoary_ssh_key_path: "{{ molecule_ephemeral_directory }}/identity_file" - name: Generate SSH key pair # Generates a new SSH key pair @@ -16,16 +16,17 @@ register: temporary_ssh_keypair # Stores the output of this task in a variable - name: Set SSH public key # Sets the SSH public key from the key pair - set_fact: + ansible.builtin.set_fact: temporary_ssh_public_key: "{{ temporary_ssh_keypair.public_key }}" - name: Create VM in KubeVirt # Calls another file to create the VM in KubeVirt - include_tasks: tasks/create_vm.yml + ansible.builtin.include_tasks: tasks/create_vm.yml loop: "{{ molecule_yml.platforms }}" # Loops over all platforms defined in molecule_yml loop_control: loop_var: vm # Sets the variable for the current item in the loop - name: Create Nodeport service if ssh_type is set to NodePort # Conditional block, executes if vm.ssh_service.type is NodePort + when: "vm.ssh_service.type == 'NodePort'" # The block is executed when this condition is met block: - name: Create ssh NodePort Kubernetes Services # Creates a new NodePort service in Kubernetes kubernetes.core.k8s: @@ -58,10 +59,9 @@ loop_control: loop_var: vm # Sets the variable for the current item in the loop register: node_port_services # Stores the output of this task in a variable - when: "vm.ssh_service.type == 'NodePort'" # The block is executed when this condition is met - name: Create VM dictionary # Calls another file to create a dictionary with information about the VM - include_tasks: tasks/create_vm_dictionary.yml + ansible.builtin.include_tasks: tasks/create_vm_dictionary.yml loop: "{{ molecule_yml.platforms }}" # Loops over all platforms defined in molecule_yml loop_control: loop_var: vm # Sets the variable for the current item in the loop @@ -76,7 +76,7 @@ ansible.builtin.copy: content: "{{ molecule_inventory | to_nice_yaml }}" dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml" - mode: 0600 # Sets the permissions of the file to -rw------- + mode: "0600" # Sets the permissions of the file to -rw------- - name: Refresh inventory # Refreshes the inventory ansible.builtin.meta: refresh_inventory diff --git a/molecule/kubevirt/tasks/create_vm_dictionary.yml b/molecule/kubevirt/tasks/create_vm_dictionary.yml index fd7dddf51d..d4b4a1b0d8 100644 --- a/molecule/kubevirt/tasks/create_vm_dictionary.yml +++ b/molecule/kubevirt/tasks/create_vm_dictionary.yml @@ -7,9 +7,9 @@ ssh_service_address: >- {%- set svc_type = vm.ssh_service.type | default(None) -%} {%- if svc_type == 'NodePort' -%} - {{(node_port_services.results | selectattr('vm.name','==',vm.name) | first)['resources'][0]['spec']['ports'][0]['nodePort'] }} + {{ (node_port_services.results | selectattr('vm.name', '==', vm.name) | first)['resources'][0]['spec']['ports'][0]['nodePort'] }} {%- endif -%} - set_fact: + ansible.builtin.set_fact: # Here, the task is updating the `molecule_systems` dictionary with new VM information. # If `molecule_systems` doesn't exist, it is created as an empty dictionary. # Then it is combined with a new dictionary for the current VM, containing ansible connection details. diff --git a/molecule/podman/create.yml b/molecule/podman/create.yml index 944b80cd77..9241a08dce 100644 --- a/molecule/podman/create.yml +++ b/molecule/podman/create.yml @@ -43,7 +43,7 @@ ansible_connection: containers.podman.podman ansible.builtin.set_fact: molecule_inventory: > - {{ molecule_inventory | combine(inventory_partial_yaml | from_yaml) }} + {{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }} loop: "{{ molecule_yml.platforms }}" loop_control: label: "{{ item.name }}" @@ -53,7 +53,7 @@ content: | {{ molecule_inventory | to_yaml }} dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml" - mode: 0600 + mode: "0600" - name: Force inventory refresh ansible.builtin.meta: refresh_inventory diff --git a/molecule/podman/molecule.yml b/molecule/podman/molecule.yml index ec9b1904dc..a2be3c33e1 100644 --- a/molecule/podman/molecule.yml +++ b/molecule/podman/molecule.yml @@ -5,3 +5,9 @@ dependency: platforms: - name: molecule-ubuntu image: ubuntu:18.04 +driver: + options: + managed: False + login_cmd_template: "podman exec -ti {instance} bash" + ansible_connection_options: + ansible_connection: podman diff --git a/playbooks/snap-pre-run.yaml b/playbooks/snap-pre-run.yaml index 5df174aea9..c34b17affa 100644 --- a/playbooks/snap-pre-run.yaml +++ b/playbooks/snap-pre-run.yaml @@ -1,4 +1,5 @@ -- hosts: all +- name: Snap-pre-run + hosts: all become: true tasks: - name: Install snapd @@ -11,13 +12,14 @@ name: snapd.socket state: started - - when: ansible_os_family == 'Debian' - name: Install snapcraft (debian) + - name: Install snapcraft (debian) + when: ansible_os_family == 'Debian' ansible.builtin.package: name: snapcraft state: present - - when: ansible_os_family == 'RedHat' + - name: Install snapcraft (RedHat) + when: ansible_os_family == 'RedHat' block: - name: Activate snapd ansible.builtin.shell: | diff --git a/src/molecule/command/create.py b/src/molecule/command/create.py index a10bca06ee..a4a96f7c7d 100644 --- a/src/molecule/command/create.py +++ b/src/molecule/command/create.py @@ -41,6 +41,11 @@ def execute(self, action_args=None): """ self._config.state.change_state("driver", self._config.driver.name) + if self._config.state.created: + msg = "Skipping, instances already created." + LOG.warning(msg) + return + self._config.provisioner.create() self._config.state.change_state("created", True) diff --git a/src/molecule/command/matrix.py b/src/molecule/command/matrix.py index 21b2be75ae..5aa7247bd1 100644 --- a/src/molecule/command/matrix.py +++ b/src/molecule/command/matrix.py @@ -30,7 +30,7 @@ class Matrix(base.Base): - """Matric Command Class. + """Matrix Command Class. .. program:: molecule matrix subcommand diff --git a/src/molecule/data/templates/scenario/create.yml.j2 b/src/molecule/data/templates/scenario/create.yml.j2 index d589bc2db4..1c9456a8e6 100644 --- a/src/molecule/data/templates/scenario/create.yml.j2 +++ b/src/molecule/data/templates/scenario/create.yml.j2 @@ -6,7 +6,6 @@ gather_facts: false # no_log: "{{ molecule_no_log }}" tasks: - # TODO: Developer must implement and populate 'server' variable - name: Create instance config @@ -34,5 +33,5 @@ {{ instance_conf | to_json | from_json | to_yaml }} dest: "{{ molecule_instance_config }}" - mode: 0600 + mode: "0600" {%- endraw %} diff --git a/src/molecule/data/templates/scenario/destroy.yml.j2 b/src/molecule/data/templates/scenario/destroy.yml.j2 index 08b95b329a..d1bd41897d 100644 --- a/src/molecule/data/templates/scenario/destroy.yml.j2 +++ b/src/molecule/data/templates/scenario/destroy.yml.j2 @@ -21,6 +21,6 @@ {{ instance_conf | to_json | from_json | to_yaml }} dest: "{{ molecule_instance_config }}" - mode: 0600 + mode: "0600" when: server.changed | default(false) | bool # noqa no-handler {%- endraw %} diff --git a/src/molecule/driver/delegated.py b/src/molecule/driver/delegated.py index f6802aea98..b89865249f 100644 --- a/src/molecule/driver/delegated.py +++ b/src/molecule/driver/delegated.py @@ -32,7 +32,7 @@ class Delegated(Driver): r"""The class responsible for managing default instances. - Delegated is `not` the default driver used in Molecule. + Delegated is the default driver used in Molecule. Under this driver, it is the developers responsibility to implement the create and destroy playbooks. ``Managed`` is the default behaviour of all diff --git a/src/molecule/interpolation.py b/src/molecule/interpolation.py index a09f86814b..8f5b198425 100644 --- a/src/molecule/interpolation.py +++ b/src/molecule/interpolation.py @@ -14,7 +14,7 @@ # Taken from Docker Compose: # https://github.com/docker/compose/blob/master/compose/config/interpolation.py -"""Iterpolation Module.""" +"""Interpolation Module.""" import string from collections.abc import MutableMapping diff --git a/src/molecule/util.py b/src/molecule/util.py index 943ea0a227..4012a926a0 100644 --- a/src/molecule/util.py +++ b/src/molecule/util.py @@ -255,7 +255,7 @@ def verbose_flag(options): """Return computed verbosity flag.""" verbose = "v" verbose_flag = [] - for _i in range(0, 3): + for _i in range(3): if options.get(verbose): verbose_flag = [f"-{verbose}"] del options[verbose]