mirror of
https://github.com/davestephens/ansible-nas
synced 2025-01-26 10:15:14 +00:00
Add reference hello_world role
This commit is contained in:
parent
1784f5663b
commit
f1ce3537b9
8 changed files with 122 additions and 0 deletions
4
nas.yml
4
nas.yml
|
@ -153,6 +153,10 @@
|
|||
- heimdall
|
||||
when: (heimdall_enabled | default(False))
|
||||
|
||||
- role: hello_world
|
||||
tags:
|
||||
- hello_world
|
||||
|
||||
- role: homeassistant
|
||||
tags:
|
||||
- homeassistant
|
||||
|
|
16
roles/hello_world/defaults/main.yml
Normal file
16
roles/hello_world/defaults/main.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
hello_world_enabled: false
|
||||
hello_world_available_externally: false
|
||||
|
||||
# directories
|
||||
hello_world_data_directory: "{{ docker_home }}/hello_world"
|
||||
|
||||
# network
|
||||
hello_world_port: "9999"
|
||||
hello_world_hostname: "hello_world"
|
||||
|
||||
# specs
|
||||
hello_world_memory: 1g
|
||||
|
||||
# docker
|
||||
hello_world_container_name: hello_world
|
15
roles/hello_world/docs/hello_world.md
Normal file
15
roles/hello_world/docs/hello_world.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Hello World
|
||||
|
||||
Homepage: <https://www.example.com/>
|
||||
|
||||
A few sentences here about what the application does.
|
||||
|
||||
## Usage
|
||||
|
||||
Set `hello_world_enabled: true` in your `inventories/<your_inventory>/nas.yml` file.
|
||||
|
||||
The Hello World web interface can be found at <http://ansible_nas_host_or_ip:9999>.
|
||||
|
||||
## Specific Configuration
|
||||
|
||||
Detail any information here about user setup steps once Ansible-NAS has started the application.
|
6
roles/hello_world/molecule/default/molecule.yml
Normal file
6
roles/hello_world/molecule/default/molecule.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
provisioner:
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
hello_world_enabled: true
|
10
roles/hello_world/molecule/default/side_effect.yml
Normal file
10
roles/hello_world/molecule/default/side_effect.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
- name: Stop
|
||||
hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: "Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }} role"
|
||||
include_role:
|
||||
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
|
||||
vars:
|
||||
hello_world_enabled: false
|
17
roles/hello_world/molecule/default/verify.yml
Normal file
17
roles/hello_world/molecule/default/verify.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
# This is an example playbook to execute Ansible tests.
|
||||
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Get container state
|
||||
docker_container_info:
|
||||
name: hello_world
|
||||
register: result
|
||||
|
||||
- name: Check Hello World is running
|
||||
assert:
|
||||
that:
|
||||
- result.container['State']['Status'] == "running"
|
||||
- result.container['State']['Restarting'] == false
|
17
roles/hello_world/molecule/default/verify_stopped.yml
Normal file
17
roles/hello_world/molecule/default/verify_stopped.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
# This is a Hello World playbook to execute Ansible tests.
|
||||
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Try and stop and remove Hello World
|
||||
docker_container:
|
||||
name: hello_world
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- name: Check Hello World is stopped
|
||||
assert:
|
||||
that:
|
||||
- not result.changed
|
37
roles/hello_world/tasks/main.yml
Normal file
37
roles/hello_world/tasks/main.yml
Normal file
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
- name: Start Hello World
|
||||
block:
|
||||
- name: Create Hello World Directories
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
with_items:
|
||||
- "{{ hello_world_data_directory }}"
|
||||
|
||||
- name: Hello World Docker Container
|
||||
docker_container:
|
||||
name: "{{ hello_world_container_name }}"
|
||||
image: crccheck/hello-world
|
||||
pull: true
|
||||
volumes:
|
||||
- "{{ hello_world_data_directory }}:/hello_world:rw"
|
||||
ports:
|
||||
- "{{ hello_world_port }}:8000"
|
||||
restart_policy: unless-stopped
|
||||
memory: "{{ hello_world_memory }}"
|
||||
labels:
|
||||
traefik.enable: "{{ hello_world_available_externally | string }}"
|
||||
traefik.http.routers.hello_world.rule: "Host(`{{ hello_world_hostname }}.{{ ansible_nas_domain }}`)"
|
||||
traefik.http.routers.hello_world.tls.certresolver: "letsencrypt"
|
||||
traefik.http.routers.hello_world.tls.domains[0].main: "{{ ansible_nas_domain }}"
|
||||
traefik.http.routers.hello_world.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
|
||||
traefik.http.services.hello_world.loadbalancer.server.port: "4040"
|
||||
when: hello_world_enabled is true
|
||||
|
||||
- name: Stop Hello World
|
||||
block:
|
||||
- name: Stop Hello World
|
||||
docker_container:
|
||||
name: "{{ hello_world_container_name }}"
|
||||
state: absent
|
||||
when: hello_world_enabled is false
|
Loading…
Reference in a new issue