Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from jeffcpullen/devspaces-3-rhel-8
Browse files Browse the repository at this point in the history
fix: backup_role enhance, docs update, rmv extra
  • Loading branch information
svor authored Jul 6, 2023
2 parents f4653bc + 04e5c3a commit 7c81f06
Show file tree
Hide file tree
Showing 35 changed files with 231 additions and 459 deletions.
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"files.associations": {
"*.yaml": "ansible",
"*.yml": "ansible"
},
"ansible.ansible.path": "/usr/local/bin/ansible",
"ansible.python.interpreterPath": "/bin/python",
"ansible.ansible.useFullyQualifiedCollectionNames": true,
"ansible.ansibleNavigator.path": "ansible-navigator",
"ansible.completion.provideModuleOptionAliases": true,
"ansible.completion.provideRedirectModules": true,
"ansible.validation.enabled": true,
"ansible.validation.lint.enabled": true,
"ansible.validation.lint.path": "/usr/local/bin/ansible-lint"
}
12 changes: 6 additions & 6 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ rules:
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
comments: enable
comments-indentation: enable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
indentation: enable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
trailing-spaces: enable
truthy: enable
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ NOTE: You will still need to configured your name/email globally the first time
git config --global user.name "Homer Simpson"
git config --global user.email [email protected]
```

## Sample Molecule Testing Role

A sample role has been provided in the roles/backup_file directory to experiment with Test Driven Development using Molecule and OpenShift DevSpaces. A molecule verifier has been configured to test that the role functions as expected.

### Automation requirements
1. Make a backup of a file identified using the backup_file_source variable
2. The backup should be stored in the directory identified by the backup_file_dest_folder variable
3. If the backup directory doesn't exist, it should be created and writable
4. The backup file should have a suffix appended such as '.bak' which is identified by the backup_file_dest_suffix variable

### To begin development against the backup_file role
1. Click the three horizontal bar icon in the top left of the window and select 'Terminal' -> 'New Terminal'
2. Click into the terminal window
3. Change directory into roles/backupfile `cd roles/backup_file`
4. Run `molecule create`. This will start a test pod for the automation to run against (defined in roles/backup_file/molecule/default/molecule.yml).
5. Run `oc get pods` to view the test instance that was created
6. Run `molecule verify` to run the verification against the test pod and see the failures to help guide the tasks necessary in the role.
7. Run `molecule converge` to run the base tasks/main.yml against the pod. This will create a backup of a file in the backup destionation folder with a suffix appended.
8. Run `molecule converge` to execute the role against the test instance, and `molecule verify` to see if any tests are still failing. Repeate this until all tests pass.

To reset your test pod back to a fresh instance you can run `molecule destroy` and then `molecule create` to recreate it. To run the full molecule test without stepping through each stage, run `molecule test`.

## Contributing

Contributions to this repository are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request. You can ask any questions in the [Ansible-ZipShip-WG gchat channel](https://chat.google.com/room/AAAA8cZvmmw?cls=7)
Expand Down
15 changes: 0 additions & 15 deletions molecule/default/INSTALL.rst

This file was deleted.

7 changes: 0 additions & 7 deletions molecule/default/converge.yml

This file was deleted.

35 changes: 0 additions & 35 deletions molecule/default/create.yml

This file was deleted.

24 changes: 0 additions & 24 deletions molecule/default/destroy.yml

This file was deleted.

32 changes: 0 additions & 32 deletions molecule/default/molecule.yml

This file was deleted.

10 changes: 0 additions & 10 deletions molecule/default/verify.yml

This file was deleted.

11 changes: 0 additions & 11 deletions molecule/podman/converge.yml

This file was deleted.

32 changes: 0 additions & 32 deletions molecule/podman/molecule.yml

This file was deleted.

14 changes: 0 additions & 14 deletions molecule/podman/verify.yml

This file was deleted.

16 changes: 15 additions & 1 deletion roles/backup_file/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ ansible-galaxy collection install -r demo/backup_file/requirements.yml
Role Variables
--------------

The sample role doesn't have any variables. It just runs a simple smoke test to validate the containers are accessible.
| Name | Required | Default | Type | Description |
| ------- | -------- | -------- | ---------- | ------------------------|
| backup_file_source | yes | '/etc/hosts' | string | The file to be backed up |
| backup_file_dest_folder | yes | '/tmp/backups' | string | The folder where backups are stored |
| backup_file_dest_suffix | no | '.bak' | string | The suffix to be appended to backup files |
| backup_file_dest_dir_owner | no | current user id | string | The owner permission for back up folder |
| backup_file_dest_dir_group | no | current group id | string | The group permission for the back up folder |
| backup_file_dest_dir_mode | no | '0750' | string | The mode permission for the backup folder |
| backup_file_dest_owner | no | current user id | string | The owner permission for the backed up file |
| backup_file_dest_group | no | current group id | string | The group permission for the backed up file |
| backup_file_dest_mode | no | '0640' | string | The mode permission for the backed up file |
| backup_file_remote_source | no | true | bool | If the source file exists on the remote system |

Dependencies
------------
Expand All @@ -60,6 +71,9 @@ Including an example of how to use your role (for instance, with variables passe
- name: Simple test case
hosts: all
connection: community.okd.oc
vars:
backup_file_source: '/etc/resolv.conf'
backup_file_dest_folder: '/tmp/backups'
roles:
- backup_file

Expand Down
10 changes: 10 additions & 0 deletions roles/backup_file/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
---
# defaults file for backup_file
backup_file_source: '/etc/hosts'
backup_file_dest_folder: '/tmp/backups'
backup_file_dest_suffix: '.bak'
backup_file_dest_dir_owner: "{{ ansible_user_id }}"
backup_file_dest_dir_group: "{{ ansible_user_gid }}"
backup_file_dest_dir_mode: '0750'
backup_file_dest_owner: "{{ ansible_user_id }}"
backup_file_dest_group: "{{ ansible_user_gid }}"
backup_file_dest_mode: '0640'
backup_file_remote_source: true
38 changes: 14 additions & 24 deletions roles/backup_file/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
galaxy_info:
author: jp
author: jeffcpullen
namespace: demo
description: Cool description
company: acme corp
description: "This is an example of a non-priviledged role using kubernetes as the driver and connection method"
company: Red Hat

license: GPL-3

min_ansible_version: '2.14'
min_ansible_version: '2.15'

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
platforms:
- name: Fedora
versions:
- '37'
- name: Fedora
versions:
- all
- name: EL
versions:
- all

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
galaxy_tags:
- system
- ansible
- automation

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
17 changes: 8 additions & 9 deletions roles/backup_file/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dependency:
name: galaxy
driver:
name: delegated
options:
options:
managed: true
ansible_connection_options:
connection: local
Expand All @@ -17,18 +17,17 @@ provisioner:
config_options:
defaults:
remote_tmp: '/tmp'
# This just says go back a directory and thats your roles path
# You can also provide this via pipeline with something like this
# ANSIBLE_ROLES_PATH: $COLLECTION_ROLES
# This just says go back a directory and thats your roles path
# You can also provide this via pipeline with something like this
# ANSIBLE_ROLES_PATH: $COLLECTION_ROLES

# COLLECTIONS_PATH: ${PROJECT_SOURCE}
# ANSIBLE_ROLES_PATH: ${PROJECT_SOURCE}/${MOLECULE_NAMESPACE}
# COLLECTIONS_PATH: ${PROJECT_SOURCE}
# ANSIBLE_ROLES_PATH: ${PROJECT_SOURCE}/${backup_file_molecule_namespace}
inventory:
group_vars:
all:
test_role_file_dest: 'demofile.txt'
molecule_namespace: ${DEVWORKSPACE_NAMESPACE}
molecule_pip_dependencies:
backup_file_molecule_namespace: ${DEVWORKSPACE_NAMESPACE}
backup_file_molecule_pip_dependencies:
- kubernetes
verifier:
name: ansible
Expand Down
Loading

0 comments on commit 7c81f06

Please sign in to comment.