Skip to content

Commit

Permalink
Enable ansible-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Oct 17, 2023
1 parent 96eedb1 commit 09db02c
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exclude_paths:
- mkdocs.yml # using tags
kinds:
- "yaml": "**/docs/*.yml"
- "yaml": "**/snap/*.yaml"
- "yaml": "**/.github/*.yml"
3 changes: 3 additions & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file contains ignores rule violations for ansible-lint
src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/meta/main.yml role-name
src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/meta/main.yml schema[meta]
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ repos:
- pytest-mock
- pytest-testinfra
- wcmatch
- repo: https://github.com/ansible/ansible-lint
rev: v6.20.3
hooks:
- id: ansible-lint
6 changes: 3 additions & 3 deletions molecule/kubevirt/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
tasks:
- name: Set default SSH key path # Sets the path of the SSH key
ansible.builtin.set_fact:
tempoary_ssh_key_path: "{{ molecule_ephemeral_directory }}/identity_file"
temporary_ssh_key_path: "{{ molecule_ephemeral_directory }}/identity_file"

- name: Generate SSH key pair # Generates a new SSH key pair
community.crypto.openssh_keypair:
path: "{{ tempoary_ssh_key_path }}"
path: "{{ temporary_ssh_key_path }}"
size: "{{ temporary_ssh_key_size }}"
register: temporary_ssh_keypair # Stores the output of this task in a variable

Expand Down Expand Up @@ -85,7 +85,7 @@
ansible.builtin.assert:
that: "'molecule' in groups"
fail_msg: "Molecule group was not found in inventory groups: {{ groups }}"
run_once: true # Ensures this task is only run once, not on every host in 'hosts'
run_once: true # noqa: run-once

- name: Validate that inventory was refreshed # New playbook to validate the inventory
hosts: molecule # Runs on hosts in the 'molecule' group
Expand Down
3 changes: 3 additions & 0 deletions playbooks/snap-pre-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
- name: Activate snapd
ansible.builtin.shell: |
ln -s /var/lib/snapd/snap /snap
changed_when: true

- name: Install snapcraft (redhat)
ansible.builtin.shell: |
type snapcraft || snap install --classic snapcraft
changed_when: true

- name: Validate snapd install
ansible.builtin.shell: |
set -e
snap version
snapcraft version
changed_when: false
6 changes: 6 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is only used for testing purposes as it helps ansible-lint to
# install dependencies when these are missing.
collections:
- community.docker
- containers.podman
- kubernetes.core
3 changes: 1 addition & 2 deletions src/molecule/test/resources/playbooks/delegated/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
hosts: localhost
connection: local
gather_facts: false
tasks:
- ansible.builtin.include: create/docker.yml
tasks: []
3 changes: 1 addition & 2 deletions src/molecule/test/resources/playbooks/delegated/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
hosts: localhost
connection: local
gather_facts: false
tasks:
- ansible.builtin.include: destroy/docker.yml
tasks: []
2 changes: 1 addition & 1 deletion src/molecule/test/resources/roles/molecule/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ galaxy_info:
author: Ansible Molecule by Red Hat
description: Test Molecule role
license: MIT
min_ansible_version: 2.5
min_ansible_version: "2.10"
platforms:
- name: GenericLinux
versions:
Expand Down
22 changes: 12 additions & 10 deletions src/molecule/test/resources/roles/molecule/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
- name: Create /etc/molecule
ansible.builtin.file: dest=/etc/molecule
group=root
owner=root
mode=0755
state=directory
ansible.builtin.file:
dest: /etc/molecule
group: root
owner: root
mode: "0755"
state: directory

- name: Create /etc/molecule/{{ ansible_host }}
ansible.builtin.copy: dest="/etc/molecule/{{ ansible_host }}"
group=root
owner=root
mode=0644
content="{{ ansible_host }}"
ansible.builtin.copy:
dest: "/etc/molecule/{{ ansible_host }}"
group: root
owner: root
mode: "0644"
content: "{{ ansible_host }}"
1 change: 1 addition & 0 deletions src/molecule/test/resources/sample-collection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
2 changes: 2 additions & 0 deletions src/molecule/test/resources/sample-collection/galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ build_ignore:

repository: https://opendev.org/openstack/tripleo-repos
license_file: LICENSE
tags:
- tools
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- name: "some task inside foo.bar collection"
- name: Some task inside foo.bar collection
ansible.builtin.debug:
msg: "hello world!"
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
ansible.builtin.debug:
msg: "{{ 'foo' | community.molecule.header }}"

- name: test installed role
- name: Test installed role
ansible.builtin.include_role:
name: ssbarnea.ansible_role_helloworld
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
collections:
- community.molecule
roles:
- ssbarnea.ansible_role_helloworld
- name: ssbarnea.ansible_role_helloworld
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
ansible.builtin.debug:
msg: "{{ 'foo' | community.molecule.header }}"

- name: test installed role
- name: Test installed role
ansible.builtin.include_role:
name: ssbarnea.ansible_role_helloworld
2 changes: 2 additions & 0 deletions src/molecule/test/scenarios/driver/delegated/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ galaxy_info:
description: Role to test ansible_compat installation of role
namespace: molecule
role_name: delegated_test
license: GPL
min_ansible_version: "2.9"
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
# noqa: role-name
dependencies: []

galaxy_info:
author: Molecule Developer
description: Role to test ansible_compat installation of role
namespace: molecule
role_name: delegated-test
license: GPL
min_ansible_version: "2.10"
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- hosts: instance
- name: Molecule test fixture
hosts: instance
gather_facts: false
tasks:
- name: Host vars host_var for host host-group-vars from molecule.yml
Expand Down Expand Up @@ -28,14 +29,16 @@
ansible.builtin.debug:
var: hostvars['extra_host']['host_group_vars_extra_host_molecule_yml']

- hosts: example
- name: Molecule test fixture
hosts: example
gather_facts: false
tasks:
- name: Dummy converge of example group
ansible.builtin.debug:
var: ansible_host

- hosts: example_1
- name: Molecule test fixture
hosts: example_1
gather_facts: false
tasks:
- name: Dummy converge of child example_1 group
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- hosts: example
- name: Molecule test fixture
hosts: example
gather_facts: false
tasks:
- name: Host vars from host_vars links
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
hosts: all
gather_facts: false
become: true
roles:
- idempotence
roles: []
17 changes: 14 additions & 3 deletions src/molecule/test/scenarios/idempotence/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
# Taken from https://github.com/ansible-community/molecule/issues/835

- name: Create /tmp/test1
ansible.builtin.file: name=/tmp/test1 state=directory
ansible.builtin.file:
name: /tmp/test1
state: directory
mode: "0600"

- name: Replace /tmp/test1 by /tmp/test2
ansible.builtin.shell: ls -ld /tmp/test1 | grep root
ansible.builtin.shell: |
set -euxo pipefail
ls -ld /tmp/test1 | grep root
changed_when: false

- name: Fix /tmp/test1 perms
ansible.builtin.file: name=/tmp/test1 state=directory owner=lp group=lp
ansible.builtin.file:
name: /tmp/test1
state: directory
owner: lp
group: lp
mode: "0600"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
ansible.builtin.file:
path: /tmp/testfile
state: touch
mode: "0644"
when: not test_file.stat.exists
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
tasks:
- name: Force a converge failure
ansible.builtin.command: /bin/false
changed_when: false

0 comments on commit 09db02c

Please sign in to comment.