Skip to content

Commit

Permalink
Add: molecule for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMehraji committed Jan 26, 2025
1 parent 301b60c commit 0ebf193
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 117 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
name: CI

'on':
pull_request:
push:
branches:
- main
schedule:
- cron: "0 7 * * 0"

defaults:
run:
working-directory: 'AliMehraji.users'

jobs:

yaml_lint:
name: Yaml Lint
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'AliMehraji.users'

- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install yamllint

- name: Lint code.
run: |
yamllint .
ansible_lint:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ansible-lint
uses: ansible/ansible-lint@main

Check failure on line 46 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Yaml Lint

46:1 [trailing-spaces] trailing spaces
molecule:
name: Molecule
runs-on: ubuntu-latest
strategy:
matrix:
distro:
- rockylinux9
- ubuntu2404
- ubuntu2204
- debian12
- debian11
- fedora40

steps:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'AliMehraji.users'

- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install -r requirements.txt

- name: Run Molecule tests.
run: molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}

...
27 changes: 0 additions & 27 deletions .github/workflows/lint.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Release

defaults:
run:
working-directory: 'alimehraji.usersrole'
working-directory: 'AliMehraji.users'

jobs:

Expand All @@ -18,7 +18,7 @@ jobs:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'alimehraji.usersrole'
path: 'AliMehraji.users'

- name: Set up Python 3.
uses: actions/setup-python@v5
Expand Down
170 changes: 85 additions & 85 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,106 +1,106 @@
---

# List of the groups to manage
users_groups: []
# users_groups: []

# Example:
# users_groups:
# # Example 1: Simple group with only the name specified
# - name: developers
users_groups:
# Example 1: Simple group with only the name specified
- name: developers

# # Example 2: Group with a specific GID
# - name: admins
# gid: 1001
# Example 2: Group with a specific GID
- name: admins
gid: 1007

# # Example 3: System group (typically has lower GID numbers)
# - name: systemgroup
# system: true
# Example 3: System group (typically has lower GID numbers)
- name: systemgroup
system: true

# # Example 4: Local group (non-system, typically for local use)
# - name: localgroup
# local: true
# Example 4: Local group (non-system, typically for local use)
# - name: localgroup
# local: true

# # Example 5: Group with custom GID and defined as a non-system local group
# - name: customgroup
# gid: 2001
# system: false
# local: true
# Example 5: Group with custom GID and defined as a non-system local group
# - name: customgroup
# gid: 2001
# system: false
# local: true

# # Example 6: Another system group with explicit GID
# - name: sysadmins
# gid: 1002
# system: true
# Example 6: Another system group with explicit GID
- name: sysadmins
gid: 1008
system: true

# # Example 7: Group with all attributes defined
# - name: fullgroup
# gid: 3001
# system: false
# local: true
# Example 7: Group with all attributes defined
# - name: fullgroup
# gid: 3001
# system: false
# local: true

# # Example 8: Group without specifying optional attributes (uses defaults)
# - name: guest
# Example 8: Group without specifying optional attributes (uses defaults)
- name: guest


# List of the users to manage
users_users: []
# users_users: []

# Examples:

# users_users:
# # Example 1: Simple user with only the name specified
# - name: alice

# # Example 2: User with a specified password
# - name: bob
# password: 'securepassword' # Replace 'securepassword' with the actual password

# # Example 3: User with a specified shell and comment
# - name: charlie
# shell: /bin/zsh
# comment: "Charlie Developer"

# # Example 4: User with a specific UID and home directory
# - name: dave
# uid: 1500
# home: /home/dave_custom

# # Example 5: User with an expiration date
# - name: eve
# expires: "2025-12-31"

# # Example 6: User assigned to a primary group and additional groups
# - name: frank
# group: developers
# groups: "docker,git"
# sudoer: true # This user will be added to the sudoer group if defined

# # Example 7: User with SSH public key and custom SSH options
# - name: grace
# ssh_key: |
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3...
# ssh_key_options:
# - no-port-forwarding
# - no-agent-forwarding
# ssh_comment: "[email protected]"

# # Example 8: System user with no home directory
# - name: systemuser
# system: true
# create_home: false

# # Example 9: User with a custom password update policy and non-unique UID
# - name: heidi
# password: 'anothersecurepassword'
# update_password: "on_create"
# non_unique: true

# # Example 10: User with creation of home directory and specific UID
# - name: judy
# uid: 2001
# create_home: true
# shell: /bin/bash
# comment: "Judy User"
# sudoer: true
users_users:
# Example 1: Simple user with only the name specified
- name: alice

# Example 2: User with a specified password
- name: bob
password: 'securepassword' # Replace 'securepassword' with the actual password

# Example 3: User with a specified shell and comment
- name: charlie
shell: /bin/zsh
comment: "Charlie Developer"

# Example 4: User with a specific UID and home directory
- name: dave
uid: 1500
home: /home/dave_custom

# Example 5: User with an expiration date
# - name: eve
# expires: "2025-12-31"

# Example 6: User assigned to a primary group and additional groups
# - name: frank
# group: developers
# groups: "docker,git"
# sudoer: true # This user will be added to the sudoer group if defined

# Example 7: User with SSH public key and custom SSH options
- name: grace
ssh_key: |
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3...
ssh_key_options:
- no-port-forwarding
- no-agent-forwarding
ssh_comment: "[email protected]"

# Example 8: System user with no home directory
- name: systemuser
system: true
create_home: false

# Example 9: User with a custom password update policy and non-unique UID
- name: heidi
password: 'anothersecurepassword'
update_password: "on_create"
non_unique: true

# Example 10: User with creation of home directory and specific UID
- name: judy
uid: 2001
create_home: true
shell: /bin/bash
comment: "Judy User"
sudoer: true

# # Example 11: User with all possible attributes defined
# - name: kate
Expand Down
2 changes: 1 addition & 1 deletion meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ argument_specs:
- If false, user is not sudoer.
append:
type: bool
default: true
default: false
description:
- If true, add the user to the groups specified in groups.
- If false, add the user to the groups specified in groups and remove from all others.
Expand Down
14 changes: 14 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Converge
hosts: all
become: true

pre_tasks:
- name: Update apt cache.
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
when: ansible_os_family == 'Debian'

roles:
- role: AliMehraji.users

Check failure on line 14 in molecule/default/converge.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

syntax-check[specific]

the role 'AliMehraji.users' was not found in /home/runner/work/ansible-role-users/ansible-role-users/molecule/default/roles:/home/runner/.cache/ansible-compat/72b20b/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-role-users/ansible-role-users/molecule/default

Check failure on line 14 in molecule/default/converge.yml

View workflow job for this annotation

GitHub Actions / Yaml Lint

14:1 [document-end] missing document end "..."
22 changes: 22 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
role_name_check: 1
dependency:
name: galaxy
options:
ignore-errors: true
requirements-file: requirements.yml
driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

Check failure on line 22 in molecule/default/molecule.yml

View workflow job for this annotation

GitHub Actions / Yaml Lint

22:1 [document-end] missing document end "..."
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ ansible
ansible-lint
yamllint

# Needed for Molecule test scenarios
molecule
molecule-plugins[docker]
docker

# Needed for jinja2 json_query templating
jmespath
# Needed for ansible.utils.validate module
jsonschema==4.23.0

aar-doc==2.0.0
ssh-keygen

2 changes: 1 addition & 1 deletion tasks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expires: "{{ item.expires | default(omit) }}"
group: "{{ item.group | default(omit) }}"
groups: "{{ (item.groups | default('') + (',' + users_user_sudoer_group if item.sudoer is defined and item.sudoer else '')) | trim or omit }}"
append: "{{ item.append | default(true) | bool }}"
append: "{{ item.append | default(false) | bool }}"
create_home: "{{ item.create_home | default(true) | bool }}"
update_password: "{{ item.update_password | default('always') }}"
non_unique: "{{ item.non_unique | default(omit) | bool }}"
Expand Down

0 comments on commit 0ebf193

Please sign in to comment.