Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Oct 17, 2023
2 parents 9a85815 + d7b93b5 commit 379ffd9
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .config/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mkdocs-ansible[lock]>=0.1.4
pipdeptree>=2.4.0
linkchecker
linkchecker==10.2.1
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: 0600
mode: "0600"
2 changes: 1 addition & 1 deletion molecule/default/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions molecule/docker/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions molecule/kubevirt/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions molecule/kubevirt/tasks/create_vm_dictionary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions molecule/podman/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions molecule/podman/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions playbooks/snap-pre-run.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- hosts: all
- name: Snap-pre-run
hosts: all
become: true
tasks:
- name: Install snapd
Expand All @@ -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: |
Expand Down
5 changes: 5 additions & 0 deletions src/molecule/command/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


class Matrix(base.Base):
"""Matric Command Class.
"""Matrix Command Class.
.. program:: molecule matrix subcommand
Expand Down
3 changes: 1 addition & 2 deletions src/molecule/data/templates/scenario/create.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,5 +33,5 @@

{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: 0600
mode: "0600"
{%- endraw %}
2 changes: 1 addition & 1 deletion src/molecule/data/templates/scenario/destroy.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
2 changes: 1 addition & 1 deletion src/molecule/driver/delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 379ffd9

Please sign in to comment.