Skip to content

Commit

Permalink
Merge pull request #42 from bulch/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bulch authored Dec 10, 2024
2 parents e3963d7 + 5ff430f commit b2f877e
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 104 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ name: CI
branches:
- master
- develop
schedule:
- cron: "0 7 * * 0"
# schedule:

Check warning on line 10 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Lint

10:3 [comments-indentation] comment not indented like content
# - cron: "0 7 * * 0"

defaults:
run:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- ubuntu2404
- ubuntu2204
- ubuntu2004
- ubuntu1804
# - ubuntu1804 # TODO: WARNING Driver docker does not provide a schema
# - ubuntu1604 # TODO: fatal: [instance]: FAILED! =>
# {
# "ansible_facts": {},
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
run: echo "qwerty" > .vault_password

- name: Run Molecule tests.
run: molecule test --all
run: molecule --debug test --all
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ansible.python.interpreterPath": "venv/bin/python"
}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ansible-galaxy role install bulch.rsync_server

## Role Variables

Default tvaribles
Default varibles

```
rsync_config_file: "/etc/rsyncd.conf"
Expand Down Expand Up @@ -72,4 +72,3 @@ MIT / BSD
## Author Information

This role was created in 2022 by [bulch](https://bulch.ru), <[email protected]>

3 changes: 1 addition & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
# defaults file for rsync_server

rsync_config_file: "/etc/rsyncd.conf"
rsync_config_port: 873
rsync_server_timeout: 300
rsync_server_max_connections: 2
rsync_packages:
- rsync
rsync_config_manage: []
rsync_config_manage: []
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ galaxy_info:
platforms:
- name: Ubuntu
versions:
- bionic
- noble
- focal
- jammy

Expand Down
47 changes: 33 additions & 14 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
---
- name: Converge

hosts: all
- name: Fail if molecule group is missing
hosts: localhost
tasks:
- name: Print some info
ansible.builtin.debug:
msg: "{{ groups }}"

pre_tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
when: ansible_os_family == "Debian"
changed_when: false
- name: Assert group existence
ansible.builtin.assert:
that: "'molecule' in groups"
fail_msg: |
molecule group was not found inside inventory groups: {{ groups }}
- name: Converge
hosts: molecule
# We disable gather facts because it would fail due to our container not
# having python installed. This will not prevent use from running 'raw'
# commands. Most molecule users are expected to use containers that already
# have python installed in order to avoid notable delays installing it.
gather_facts: false
vars:
rsync_config_manage:
- name: "example-storage"
Expand All @@ -21,12 +29,23 @@
secrets:
user: "9D0EeojsHCU"
password: "068tg5jLVv4"

pre_tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
# when: ansible_os_family == "Debian"
changed_when: false
tasks:
- name: Include bulch.rsync_server
ansible.legacy.include_role:
name: "bulch.rsync_server"

- name: Debug inventory_hostname
ansible.legacy.debug:
msg: "{{ inventory_hostname }}"
- name: Check uname
ansible.builtin.raw: uname -a
register: result
changed_when: false

- name: Print some info
ansible.builtin.assert:
that: result.stdout | regex_search("^Linux")
80 changes: 80 additions & 0 deletions molecule/default/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
- name: Create
hosts: localhost
gather_facts: false
vars:
molecule_inventory:
all:
hosts: {}
molecule: {}
tasks:
- name: Create a container
community.docker.docker_container:
name: "{{ item.name }}"
image: "{{ item.image }}"
state: started
command: sleep 1d
log_driver: json-file
register: result
loop: "{{ molecule_yml.platforms }}"

- name: Print some info
ansible.builtin.debug:
msg: "{{ result.results }}"

- name: Fail if container is not running
when: >
item.container.State.ExitCode != 0 or
not item.container.State.Running
ansible.builtin.include_tasks:
file: tasks/create-fail.yml
loop: "{{ result.results }}"
loop_control:
label: "{{ item.container.Name }}"

- name: Add container to molecule_inventory
vars:
inventory_partial_yaml: |
all:
children:
molecule:
hosts:
"{{ item.name }}":
ansible_connection: community.docker.docker
ansible.builtin.set_fact:
molecule_inventory: >
{{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }}
loop: "{{ molecule_yml.platforms }}"
loop_control:
label: "{{ item.name }}"

- name: Dump molecule_inventory
ansible.builtin.copy:
content: |
{{ molecule_inventory | to_yaml }}
dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
mode: "0600"

- name: Force inventory refresh
ansible.builtin.meta: refresh_inventory

- name: Fail if molecule group is missing
ansible.builtin.assert:
that: "'molecule' in groups"
fail_msg: |
molecule group was not found inside inventory groups: {{ groups }}
run_once: true # noqa: run-once[task]

# we want to avoid errors like "Failed to create temporary directory"
- name: Validate that inventory was refreshed
hosts: molecule
gather_facts: false
tasks:
- name: Check uname
ansible.builtin.raw: uname -a
register: result
changed_when: false

- name: Display uname info
ansible.builtin.debug:
msg: "{{ result.stdout }}"
95 changes: 35 additions & 60 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,60 @@ dependency:
ignore-certs: true
ignore-errors: true
role-file: requirements.yml
requirements-file: collections.yml
requirements-file: requirements.yml

driver:
name: docker

platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest"
- name: molecule-ubuntu
# image: ubuntu:18.04
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest"
published_ports:
- 0.0.0.0:873:873/tcp
exposed_ports:
- 80/tcp
- 443/tcp
published_ports:
- 0.0.0.0:873:873/tcp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- /dev/null:/dev/null:rw
# command: /sbin/init
command: ${MOLECULE_DOCKER_COMMAND:-""}
tmpfs:
- /run
- /tmp
capabilities:
- SYS_ADMIN
cgroupns_mode: host
privileged: true
pre_build_image: true
- 873/tcp

provisioner:
# platforms:
# - name: instance
# image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest"
# exposed_ports:
# - 80/tcp
# - 443/tcp
# published_ports:
# - 0.0.0.0:873:873/tcp
# volumes:
# - /sys/fs/cgroup:/sys/fs/cgroup:rw
# - /dev/null:/dev/null:rw
# # command: /sbin/init
# command: ${MOLECULE_DOCKER_COMMAND:-""}
# tmpfs:
# - /run
# - /tmp
# capabilities:
# - SYS_ADMIN
# cgroupns_mode: host
# privileged: true
# pre_build_image: true

provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

inventory:
host_vars:
instance:
molecule-ubuntu:
ansible_user: root


verifier:
name: ansible

scenario:
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:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- side_effect
- verify
- cleanup
- destroy

# lint: |
# set -e
# yamllint .
# ansible-lint .
lint: |
set -e
yamllint .
ansible-lint .
4 changes: 3 additions & 1 deletion molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
# Install a role from Ansible Galaxy.
roles: []
collections:
- name: community.docker
version: ">=3.10.4"
4 changes: 4 additions & 0 deletions molecule/default/roles/test-rsync_server/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
path_default_config_rsync: "/etc/default/rsync"
path_secret_rsync: "/etc/rsyncd.secrets"
path_rsync_config: "/etc/rsyncd.conf"
14 changes: 14 additions & 0 deletions molecule/default/roles/test-rsync_server/tasks/create-fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Retrieve container log
ansible.builtin.command:
cmd: >-
{% raw %}
docker logs
{% endraw %}
{{ item.stdout_lines[0] }}
changed_when: false
register: logfile_cmd

- name: Display container log
ansible.builtin.fail:
msg: "{{ logfile_cmd.stderr }}"
22 changes: 17 additions & 5 deletions molecule/default/roles/test-rsync_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,27 @@
- secret_rsync.stat.pw_name == 'root'
- secret_rsync.stat.gr_name == 'root'

- name: Test rsync service status
ansible.builtin.service:
name: "rsync"
register: service_status_rsync
# - name: Test rsync service status
# ansible.builtin.service:
# name: "rsync"
# register: service_status_rsync
- name: Populate service facts
ansible.builtin.service_facts:

- name: Print service facts
ansible.builtin.debug:
var: ansible_facts.services

- name: Show names of existing systemd services
ansible.builtin.debug: msg={{ existing_systemd_services | map(attribute='name') }}
vars:
known_systemd_services: "{{ ansible_facts['services'].values() | selectattr('source', 'equalto', 'systemd') }}"
existing_systemd_services: "{{ known_systemd_services | rejectattr('status', 'equalto', 'not-found') }}"

- name: Test assert rsync service status
ansible.builtin.assert:
that:
- service_status_rsync['status']['ActiveState'] == 'active'
- ansible_facts.services.rsync['state'] == 'running'

- name: Gather facts on listening ports
community.general.listen_ports_facts:
Expand Down
4 changes: 0 additions & 4 deletions molecule/default/roles/test-rsync_server/vars/main.yml

This file was deleted.

Loading

0 comments on commit b2f877e

Please sign in to comment.