forked from Mirrors/cookiecutter-ansible-role
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7ab4f5155 | |||
| f03ca6d168 | |||
| f417e1828d | |||
| a412940e75 | |||
| bda1f187c5 | |||
| 8adf037392 |
@@ -2,6 +2,15 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
### [1.1.1](https://git.laurivan.com/Dev/cookiecutter-ansible-role-docker/compare/v1.1.0...v1.1.1) (2023-04-30)
|
||||
|
||||
## [1.1.0](https://git.laurivan.com/Dev/cookiecutter-ansible-role-docker/compare/v1.0.3...v1.1.0) (2023-04-27)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Better default configuration. ([bda1f18](https://git.laurivan.com/Dev/cookiecutter-ansible-role-docker/commit/bda1f187c5b2c02042c8d34ddde5bec5b77a13f9))
|
||||
|
||||
### [1.0.3](https://git.laurivan.com/Dev/cookiecutter-ansible-role-docker/compare/v1.0.2...v1.0.3) (2023-02-16)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# {{ cookiecutter.app_name | replace('_',' ') | title }} Ansible role
|
||||
|
||||
This role installs Mealie via Docker compose.
|
||||
This role installs {{ cookiecutter.app_name | title }} via Docker compose.
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -23,7 +23,7 @@ You need a machine with docker and docker-compose installed.
|
||||
```yml
|
||||
- hosts: servers
|
||||
roles:
|
||||
- 'laurivan.{{ cookiecutter.app_name | replace('_',' ') | title }}'
|
||||
- 'laurivan.{{ cookiecutter.app_name | replace('_',' ') }}'
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
---
|
||||
|
||||
## General
|
||||
# Version
|
||||
{{ cookiecutter.app_name }}_version: 1.0.0
|
||||
{{ cookiecutter.app_name }}_image: {{ cookiecutter.app_name }}:latest
|
||||
|
||||
# {{ cookiecutter.app_name }} paths
|
||||
{{ cookiecutter.app_name }}_root_path: /opt/{{ cookiecutter.app_name }}
|
||||
{{ cookiecutter.app_name }}_config_path: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_root_path {% raw %}}}{% endraw %}/conf"
|
||||
{{ cookiecutter.app_name }}_http_port: {{ cookiecutter.http_port }}
|
||||
|
||||
# {{ cookiecutter.app_name | title }} paths
|
||||
{{ cookiecutter.app_name }}_root_path: /var/local
|
||||
{{ cookiecutter.app_name }}_data_base: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_root_path {% raw %}}}{% endraw %}/{{ cookiecutter.app_name }}"
|
||||
{{ cookiecutter.app_name }}_config_path: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_root_path {% raw %}}}{% endraw %}/conf/{{ cookiecutter.app_name }}"
|
||||
|
||||
# Add other paths here to make sure they're created automatically
|
||||
#
|
||||
{{ cookiecutter.app_name }}_skeleton_paths:
|
||||
- "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path {% raw %}}}{% endraw %}"
|
||||
|
||||
# Add more templates to be copied into the config
|
||||
{{ cookiecutter.app_name }}_configuration_files:
|
||||
- "{% raw %}docker-compose.yml{% endraw %}"
|
||||
- "env.{{ cookiecutter.app_name }}.conf"
|
||||
|
||||
# Documentation
|
||||
{{ cookiecutter.app_name }}_documentation_link: "{{ cookiecutter.documentation_URL }}"
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
galaxy_info:
|
||||
author: {{ cookiecutter.author }}
|
||||
namespace: {{ cookiecutter.namespace }}
|
||||
company: {% if cookiecutter.company != "" %}{{ cookiecutter.company }}{% endif %}
|
||||
{% if cookiecutter.company != "" %} company: {{ cookiecutter.company }}{% endif %}
|
||||
role_name: {{ cookiecutter.app_name }}
|
||||
description: {{ cookiecutter.app_name | replace('_',' ') | title }} Role
|
||||
min_ansible_version: {{ cookiecutter.min_ansible_version }}
|
||||
min_ansible_container_version: {{ cookiecutter.min_ansible_container_version }}
|
||||
min_ansible_version: "{{ cookiecutter.min_ansible_version }}"
|
||||
min_ansible_container_version: "{{ cookiecutter.min_ansible_container_version }}"
|
||||
license: {{ cookiecutter.license }}
|
||||
galaxy_tags:
|
||||
- {{ cookiecutter.galaxy_tag_1 }}
|
||||
@@ -19,6 +19,6 @@ galaxy_info:
|
||||
- {{ ver }}{% endfor %}
|
||||
{% endif %}{% if cookiecutter.platforms.ubuntu_list %}
|
||||
- name: Ubuntu
|
||||
versions: {% for ver in cookiecutter.platforms.ubuntu_list %}
|
||||
versions:{% for ver in cookiecutter.platforms.ubuntu_list %}
|
||||
- {{ ver }}{% endfor %}
|
||||
{% endif %}
|
||||
@@ -3,21 +3,25 @@
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Check if the docker-compose file exists.
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Load the defaults."
|
||||
ansible.builtin.include_vars:
|
||||
dir: "../../defaults"
|
||||
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Check if the docker-compose file exists."
|
||||
ansible.builtin.stat:
|
||||
path: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path | expanduser | realpath {% raw %}}}{% endraw %}/docker-compose.yml"
|
||||
register: docker_compose_file
|
||||
register: "docker_compose_file"
|
||||
|
||||
- name: Remove docker-compose.
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Remove docker-compose."
|
||||
community.docker.docker_compose:
|
||||
project_src: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path | expanduser | realpath {% raw %}}}{% endraw %}/"
|
||||
project_src: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path | expanduser | realpath {% raw %}}}{% endraw %}/"
|
||||
build: false
|
||||
state: absent
|
||||
when: docker_compose_file.stat.exists
|
||||
when: "docker_compose_file.stat.exists"
|
||||
become: false
|
||||
|
||||
- name: Remove the docker-compose file
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Remove the docker-compose file"
|
||||
ansible.builtin.file:
|
||||
path: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path | expanduser | realpath {% raw %}}}{% endraw %}/docker-compose.yml"
|
||||
state: absent
|
||||
when: docker_compose_file.stat.exists
|
||||
path: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path | expanduser | realpath {% raw %}}}{% endraw %}/docker-compose.yml"
|
||||
state: "absent"
|
||||
when: "docker_compose_file.stat.exists"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: {{ cookiecutter.app_name }}_group
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Converge"
|
||||
hosts: "{{ cookiecutter.app_name }}_group"
|
||||
roles:
|
||||
- role: "{{cookiecutter.namespace}}.{{ cookiecutter.app_name }}"
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
---
|
||||
- name: Destroy
|
||||
hosts: localhost
|
||||
connection: local
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Destroy"
|
||||
hosts: "localhost"
|
||||
connection: "local"
|
||||
gather_facts: false
|
||||
no_log: "{% raw %}{{ molecule_no_log }}{% endraw %}"
|
||||
tasks:
|
||||
# Developer must implement.
|
||||
- name: Remove the docker image
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Remove the docker image"
|
||||
community.docker.docker_container:
|
||||
name: {{ cookiecutter.app_name }}
|
||||
state: absent
|
||||
name: "{{ cookiecutter.app_name }}"
|
||||
state: "absent"
|
||||
|
||||
# Mandatory configuration for Molecule to function.
|
||||
|
||||
- name: Populate instance config
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Populate instance config"
|
||||
ansible.builtin.set_fact:
|
||||
instance_conf: {}
|
||||
|
||||
- name: Dump instance config
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Dump instance config"
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
# Molecule managed
|
||||
{% raw %}{{ instance_conf | to_json | from_json | to_yaml }}{% endraw %}
|
||||
dest: "{% raw %}{{ molecule_instance_config }}{% endraw %}"
|
||||
mode: 0600
|
||||
when: server.changed | default(false) | bool
|
||||
when: "server.changed | default(false) | bool"
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
---
|
||||
- name: Setup the test machine
|
||||
hosts: {{ cookiecutter.app_name }}
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Setup the test machine"
|
||||
hosts: "{{ cookiecutter.app_name }}"
|
||||
tasks:
|
||||
- name: Check if /var/run/docker.sock already exists
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Check if /var/run/docker.sock already exists"
|
||||
ansible.builtin.stat:
|
||||
path: "/var/run/docker.sock"
|
||||
register: docker_sock_stat
|
||||
register: "docker_sock_stat"
|
||||
|
||||
- name: Create docker.sock
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Create docker.sock"
|
||||
ansible.builtin.raw: touch /var/run/docker.sock
|
||||
become: true
|
||||
changed_when: false
|
||||
when: not docker_sock_stat.stat.exists
|
||||
when: "not docker_sock_stat.stat.exists"
|
||||
|
||||
- name: Move docker.sock from tmp
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Move docker.sock from tmp"
|
||||
ansible.builtin.raw: >
|
||||
mount --move /tmp/docker_mounted.sock /var/run/docker.sock
|
||||
become: true
|
||||
changed_when: false
|
||||
when: not docker_sock_stat.stat.exists
|
||||
when: "not docker_sock_stat.stat.exists"
|
||||
|
||||
- name: Update apt cache.
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Update apt cache."
|
||||
ansible.builtin.apt: update_cache=yes cache_valid_time=600
|
||||
when: ansible_os_family == 'Debian'
|
||||
when: "ansible_os_family == 'Debian'"
|
||||
|
||||
- name: Install python requests
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Install python requests"
|
||||
ansible.builtin.pip:
|
||||
name:
|
||||
- requests
|
||||
- docker
|
||||
- docker-compose
|
||||
- "requests"
|
||||
- "docker"
|
||||
- "docker-compose"
|
||||
|
||||
- name: Install docker
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Install docker"
|
||||
vars:
|
||||
docker_service_manage: false
|
||||
ansible.builtin.include_role:
|
||||
name: geerlingguy.docker
|
||||
name: "geerlingguy.docker"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
---
|
||||
roles:
|
||||
- geerlingguy.docker
|
||||
- "geerlingguy.docker"
|
||||
collections: []
|
||||
|
||||
@@ -5,54 +5,54 @@
|
||||
|
||||
- name: Verify {{ cookiecutter.app_name | replace('_',' ') }}
|
||||
hosts:
|
||||
- {{ cookiecutter.app_name }}
|
||||
- "{{ cookiecutter.app_name }}"
|
||||
become: true
|
||||
vars:
|
||||
goss_version: v0.3.16
|
||||
goss_arch: amd64
|
||||
goss_dst: /usr/local/bin/goss
|
||||
goss_sha256sum: 827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb
|
||||
goss_version: "v0.3.16"
|
||||
goss_arch: "amd64"
|
||||
goss_dst: "/usr/local/bin/goss"
|
||||
goss_sha256sum: "827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb"
|
||||
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{% raw %}{{{% endraw %} goss_version {% raw %}}}{% endraw %}/goss-linux-{% raw %}{{{% endraw %} goss_arch {% raw %}}}{% endraw %}"
|
||||
goss_test_directory: /tmp
|
||||
goss_format: documentation
|
||||
goss_test_directory:" /tmp"
|
||||
goss_format: "documentation"
|
||||
|
||||
vars_files:
|
||||
- ../../defaults/main.yml
|
||||
|
||||
tasks:
|
||||
- name: Download and install Goss
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Download and install Goss"
|
||||
get_url:
|
||||
url: "{% raw %}{{{% endraw %} goss_url {% raw %}}}{% endraw %}"
|
||||
dest: "{% raw %}{{{% endraw %} goss_dst {% raw %}}}{% endraw %}"
|
||||
checksum: "sha256{% raw %}:{{{% endraw %} goss_sha256sum {% raw %}}}{% endraw %}"
|
||||
mode: 0755
|
||||
register: download_goss
|
||||
until: download_goss is succeeded
|
||||
register: "download_goss"
|
||||
until: "download_goss is succeeded"
|
||||
retries: 3
|
||||
|
||||
- name: Copy Goss tests to remote
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Copy Goss tests to remote"
|
||||
template:
|
||||
src: "{% raw %}{{{% endraw %} item {% raw %}}}{% endraw %}"
|
||||
dest: "{% raw %}{{{% endraw %} goss_test_directory {% raw %}}}{% endraw %}/{% raw %}{{{% endraw %} item | basename {% raw %}}}{% endraw %}"
|
||||
with_fileglob:
|
||||
- "tests/test_*.yml"
|
||||
|
||||
- name: Register test files
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Register test files"
|
||||
shell: "ls {% raw %}{{{% endraw %} goss_test_directory {% raw %}}}{% endraw %}/test_*.yml"
|
||||
register: test_files
|
||||
register: "test_files"
|
||||
|
||||
- name: Execute Goss tests
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Execute Goss tests"
|
||||
command: "{% raw %}{{{% endraw %} goss_dst {% raw %}}}{% endraw %} -g {% raw %}{{{% endraw %} item {% raw %}}}{% endraw %} validate --format {% raw %}{{{% endraw %} goss_format {% raw %}}}{% endraw %}"
|
||||
register: test_results
|
||||
register: "test_results"
|
||||
with_items: "{% raw %}{{{% endraw %} test_files.stdout_lines {% raw %}}}{% endraw %}"
|
||||
ignore_errors: true
|
||||
|
||||
- name: Display details about the Goss results
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Display details about the Goss results"
|
||||
debug:
|
||||
msg: "{% raw %}{{{% endraw %} item.stdout_lines {% raw %}}}{% endraw %}"
|
||||
with_items: "{% raw %}{{{% endraw %} test_results.results {% raw %}}}{% endraw %}"
|
||||
|
||||
- name: Fail when tests fail
|
||||
- name: "{{ cookiecutter.app_name | upper }} | Fail when tests fail"
|
||||
fail:
|
||||
msg: "Goss failed to validate"
|
||||
when: item.rc != 0
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
src: "{%raw%}{{{%endraw%} item {%raw%}}}{%endraw%}.j2"
|
||||
dest: "{%raw%}{{{%endraw%} {{ cookiecutter.app_name }}_config_path | expanduser | realpath {%raw%}}}{%endraw%}/{%raw%}{{{%endraw%} item {%raw%}}}{%endraw%}"
|
||||
mode: '0640'
|
||||
loop:
|
||||
- "docker-compose.yml"
|
||||
with_items:
|
||||
- "{%raw%}{{{%endraw%} {{ cookiecutter.app_name }}_configuration_files {%raw%}}}{%endraw%}"
|
||||
tags:
|
||||
- {{ cookiecutter.app_name }}_configure
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
# {{ cookiecutter.app_name }} docker compose
|
||||
version: '3.9'
|
||||
services:
|
||||
{{ cookiecutter.app_name}}:
|
||||
image: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_image {% raw %}}}{% endraw %}"
|
||||
container_name: {{ cookiecutter.app_name }}-service
|
||||
restart: always
|
||||
env_file:
|
||||
- "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path | expanduser {% raw %}}}{% endraw %}/env.{{ cookiecutter.app_name }}.conf"
|
||||
ports:
|
||||
- "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_http_port {% raw %}}}{% endraw %}"
|
||||
# Add more ports if necessary
|
||||
networks:
|
||||
- {{ cookiecutter.app_name }}-net
|
||||
# optional
|
||||
volumes:
|
||||
- "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_volume {% raw %}}}{% endraw %}"
|
||||
depends_on:
|
||||
- other
|
||||
- services
|
||||
|
||||
volumes:
|
||||
- "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_volume {% raw %}}}{% endraw %}"
|
||||
|
||||
networks:
|
||||
{{ cookiecutter.app_name }}-net: {}
|
||||
@@ -0,0 +1,2 @@
|
||||
# Add environment variables for {{ cookiecutter.app_name }} here
|
||||
# Note: This is a .ini file format
|
||||
@@ -2,6 +2,7 @@
|
||||
"comment_0":"The role name will be the value you assign to app_name with _role appended",
|
||||
"comment_1":"Introduce in exec_name the executable file name, you can change it later in the defaults/main.yml if you don't know it",
|
||||
"app_name": "",
|
||||
"http_port": "3000",
|
||||
"github_user": "equinoxel",
|
||||
"patreon_user": "laurivan",
|
||||
"company": "",
|
||||
@@ -13,8 +14,8 @@
|
||||
"molecule_version": "4.0.4",
|
||||
"python_docker_version": "6.0.1",
|
||||
"molecule_docker_version": "2.1.0",
|
||||
"ansible_lint_version":"6.12.2",
|
||||
"yamllint_version": "1.29.0",
|
||||
"ansible_lint_version":"6.14.4",
|
||||
"yamllint_version": "1.30.0",
|
||||
"license":"MIT",
|
||||
"galaxy_tag_1":"tag1",
|
||||
"galaxy_tag_2":"tag2",
|
||||
@@ -26,5 +27,5 @@
|
||||
"has_files":["True", "False"],
|
||||
"has_handlers":["True", "False"],
|
||||
"has_templates":["True", "False"],
|
||||
"documentation_URL":""
|
||||
"documentation_URL":"https://www.laurivan.com"
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ def checkInput():
|
||||
print("Error: app_name should not have _role or -role at the end, try again without it")
|
||||
print(" The name of the role will the value you introduce in app_name plus _role appended")
|
||||
sys.exit(1)
|
||||
if not moleculeVersion.startswith("3"):
|
||||
print("Error: Only supported molecule version 3.x.x, please change it and try again")
|
||||
if not (moleculeVersion.startswith("3") or moleculeVersion.startswith("4")):
|
||||
print("Error: Only supported molecule version 3.x.x or 4.x.x, please change it and try again")
|
||||
sys.exit(1)
|
||||
|
||||
def configureRole():
|
||||
|
||||
Reference in New Issue
Block a user