diff --git a/ansible-role-{{cookiecutter.app_name}}/README.md b/ansible-role-{{cookiecutter.app_name}}/README.md index 5aa5c0f..58b6715 100644 --- a/ansible-role-{{cookiecutter.app_name}}/README.md +++ b/ansible-role-{{cookiecutter.app_name}}/README.md @@ -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 diff --git a/ansible-role-{{cookiecutter.app_name}}/defaults/main.yml b/ansible-role-{{cookiecutter.app_name}}/defaults/main.yml index f7c10c9..1fca10a 100644 --- a/ansible-role-{{cookiecutter.app_name}}/defaults/main.yml +++ b/ansible-role-{{cookiecutter.app_name}}/defaults/main.yml @@ -22,5 +22,3 @@ # Documentation {{ cookiecutter.app_name }}_documentation_link: "{{ cookiecutter.documentation_URL }}" - - diff --git a/ansible-role-{{cookiecutter.app_name}}/meta/main.yml b/ansible-role-{{cookiecutter.app_name}}/meta/main.yml index 1956ef9..940002a 100644 --- a/ansible-role-{{cookiecutter.app_name}}/meta/main.yml +++ b/ansible-role-{{cookiecutter.app_name}}/meta/main.yml @@ -3,7 +3,7 @@ galaxy_info: author: {{ cookiecutter.author }} namespace: {{ cookiecutter.namespace }} - {% if cookiecutter.company != "" %}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 }}" diff --git a/ansible-role-{{cookiecutter.app_name}}/molecule/default/cleanup.yml b/ansible-role-{{cookiecutter.app_name}}/molecule/default/cleanup.yml index be340d3..036edf5 100644 --- a/ansible-role-{{cookiecutter.app_name}}/molecule/default/cleanup.yml +++ b/ansible-role-{{cookiecutter.app_name}}/molecule/default/cleanup.yml @@ -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 \ No newline at end of file + path: "{% raw %}{{{% endraw %} {{ cookiecutter.app_name }}_config_path | expanduser | realpath {% raw %}}}{% endraw %}/docker-compose.yml" + state: "absent" + when: "docker_compose_file.stat.exists" diff --git a/ansible-role-{{cookiecutter.app_name}}/molecule/default/converge.yml b/ansible-role-{{cookiecutter.app_name}}/molecule/default/converge.yml index f9efd70..5c61517 100644 --- a/ansible-role-{{cookiecutter.app_name}}/molecule/default/converge.yml +++ b/ansible-role-{{cookiecutter.app_name}}/molecule/default/converge.yml @@ -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 }}" diff --git a/ansible-role-{{cookiecutter.app_name}}/molecule/default/destroy.yml b/ansible-role-{{cookiecutter.app_name}}/molecule/default/destroy.yml index 3f4de01..47d9b89 100644 --- a/ansible-role-{{cookiecutter.app_name}}/molecule/default/destroy.yml +++ b/ansible-role-{{cookiecutter.app_name}}/molecule/default/destroy.yml @@ -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" diff --git a/ansible-role-{{cookiecutter.app_name}}/molecule/default/prepare.yml b/ansible-role-{{cookiecutter.app_name}}/molecule/default/prepare.yml index e2bd23b..ba2affa 100644 --- a/ansible-role-{{cookiecutter.app_name}}/molecule/default/prepare.yml +++ b/ansible-role-{{cookiecutter.app_name}}/molecule/default/prepare.yml @@ -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" diff --git a/ansible-role-{{cookiecutter.app_name}}/molecule/default/requirements.yml b/ansible-role-{{cookiecutter.app_name}}/molecule/default/requirements.yml index a6284de..f51f987 100644 --- a/ansible-role-{{cookiecutter.app_name}}/molecule/default/requirements.yml +++ b/ansible-role-{{cookiecutter.app_name}}/molecule/default/requirements.yml @@ -1,4 +1,4 @@ --- roles: - - geerlingguy.docker + - "geerlingguy.docker" collections: [] diff --git a/ansible-role-{{cookiecutter.app_name}}/molecule/default/verify.yml b/ansible-role-{{cookiecutter.app_name}}/molecule/default/verify.yml index 94e9691..61e802e 100644 --- a/ansible-role-{{cookiecutter.app_name}}/molecule/default/verify.yml +++ b/ansible-role-{{cookiecutter.app_name}}/molecule/default/verify.yml @@ -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