Skip to content

Instantly share code, notes, and snippets.

@apatard
Created July 11, 2023 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apatard/5ac88bbebc3409c3b896597a4621d1f6 to your computer and use it in GitHub Desktop.
Save apatard/5ac88bbebc3409c3b896597a4621d1f6 to your computer and use it in GitHub Desktop.
molecule pr3957
mkdir -p acme.myrole
cat > acme.myrole/.yamllint <<EOF
---
# Based on ansible-lint config
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
EOF
mkdir -p acme.myrole/meta
cat > acme.myrole/meta/main.yml <<EOF
---
galaxy_info:
author: Arnaud Patard
namespace: acme
role_name: myrole
description: test role
company: hupstream
license: MIT
min_ansible_version: "2.1"
galaxy_tags: []
dependencies: []
EOF
mkdir -p acme.myrole/molecule/default
cat > acme.myrole/molecule/default/verify.yml <<EOF
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Reset connection
ansible.builtin.meta: reset_connection
EOF
mkdir -p acme.myrole/molecule/default
cat > acme.myrole/molecule/default/INSTALL.rst <<EOF
***********************************
Delegated driver installation guide
***********************************
Requirements
============
This driver is delegated to the developer. Up to the developer to implement
requirements.
Install
=======
This driver is delegated to the developer. Up to the developer to implement
requirements.
EOF
mkdir -p acme.myrole/molecule/default
cat > acme.myrole/molecule/default/molecule.yml <<EOF
---
dependency:
name: galaxy
driver:
name: delegated
platforms:
- name: instance
provisioner:
name: ansible
verifier:
name: ansible
EOF
mkdir -p acme.myrole/molecule/default
cat > acme.myrole/molecule/default/converge.yml <<EOF
---
- name: Converge
hosts: all
gather_facts: false
tasks:
- name: "Include acme.myrole"
ansible.builtin.include_role:
name: "acme.myrole"
EOF
mkdir -p acme.myrole/molecule/default
cat > acme.myrole/molecule/default/destroy.yml <<EOF
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
# Developer must implement.
# Mandatory configuration for Molecule to function.
- name: Populate instance config
ansible.builtin.set_fact:
instance_conf: {}
- name: Dump instance config
ansible.builtin.copy:
content: |
# Molecule managed
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: 0600
when: server.changed | default(false) | bool # noqa no-handler
EOF
mkdir -p acme.myrole/molecule/default
cat > acme.myrole/molecule/default/create.yml <<EOF
---
- name: Create instance configuration
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Create molecule configuration file
block:
- name: Populate instances config dict
ansible.builtin.set_fact:
instance_conf: [
{'instance': "instance",
'address': "127.0.0.2",
'user': "rtp",
'port': "22"}]
- name: Dump instance config
ansible.builtin.copy: # noqa template-instead-of-copy
content: "{{ instance_conf | to_json | from_json | to_yaml }}"
dest: "{{ molecule_instance_config }}"
mode: 0600
EOF
mkdir -p acme.myrole/tasks
cat > acme.myrole/tasks/main.yml <<EOF
---
- name: Debug
ansible.builtin.debug:
msg: "Hello"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment