Skip to content

Commit

Permalink
feat: prerequisites for compose-based service deployment (#9)
Browse files Browse the repository at this point in the history
* refactor: move to main subdir

* refactor(vars): docker vars section

* feat: change directory structure

BREAKING CHANGE

* chore: add file template for env vars

* lint: resolve yamllint errors
  • Loading branch information
netr0m authored Jul 16, 2024
1 parent 97ad0ff commit 538131a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 34 deletions.
16 changes: 6 additions & 10 deletions defaults/main.yml → defaults/main/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ infra_directory_path: '/opt/infra'
infra_directory_owner: "{{ infra_user_name }}"
infra_directory_group: "{{ infra_group_name }}"
infra_directory_mode: 740
# Subdirectories
infra_subdirectories:
cfg:
path: "{{ infra_directory_path }}/cfg"
log:
path: "{{ infra_directory_path }}/log"
data:
path: "{{ infra_directory_path }}/data"

### Services ###
### Docker ###
# Default restart policy
infra_restart_policy: 'always'
infra_restart_policy: always
# Max. wait time for compose deployment
infra_compose_wait_timeout: 60

### Services ###
# Whether to force pull container images
infra_force_pull: false
# Configure Graylog
Expand Down
10 changes: 5 additions & 5 deletions tasks/deploy_pihole.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
community.docker.docker_network_info:
name: "{{ svc_docker_network_name }}"
register: _svc_net_res

- name: Set svc_network_subnet fact
ansible.builtin.set_fact:
_svc_network_subnet: "{{ _svc_net_res.network.IPAM.Config[0].Subnet }}"
Expand Down Expand Up @@ -82,10 +82,10 @@
- name: Set DNS environment variable setting for pihole
ansible.builtin.set_fact:
infra_pihole_env_vars_dns: {
'PIHOLE_DNS_': "{{
_infra_unbound_container_deployment.container.NetworkSettings.Networks[svc_docker_network_name].IPAddress +
'#' + (infra_unbound_listening_port | string)
if infra_use_unbound else ''
'PIHOLE_DNS_': "{{
_infra_unbound_container_deployment.container.NetworkSettings.Networks[svc_docker_network_name].IPAddress +
'#' + (infra_unbound_listening_port | string)
if infra_use_unbound else ''
}}"
}
when:
Expand Down
8 changes: 0 additions & 8 deletions tasks/directories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,4 @@
group: "{{ infra_directory_group }}"
mode: "{{ infra_directory_mode }}"

- name: Ensure infra_directory subdirectories are present
ansible.builtin.file:
path: "{{ item.value.path }}"
state: directory
owner: "{{ item.value.owner | default(infra_directory_owner) }}"
group: "{{ item.value.group | default(infra_directory_group) }}"
mode: "{{ item.value.mode | default(infra_directory_mode) }}"
with_dict: "{{ infra_subdirectories }}"
...
11 changes: 0 additions & 11 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
---
- name: Load OS-specific vars
ansible.builtin.include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
- 'main.yml'
paths:
- 'vars'

# Gather user facts
- name: Include 'user_facts' tasks
ansible.builtin.import_tasks: user_facts.yml
Expand Down
4 changes: 4 additions & 0 deletions templates/template.env.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# {{ ansible_managed }}
{% for key, val in _env_vars.items() %}
{{ key }}={{ val }}
{% endfor %}
5 changes: 5 additions & 0 deletions vars/main.yml → vars/main/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
### Docker ###
# Shared labels for the Docker volumes
infra_docker_volume_shared_labels:
netr0m.ansible-role: infra

# Environment variables for the Unifi container
infra_unifi_env_vars:
PUID: "{{ infra_user_uid | string }}"
Expand Down

0 comments on commit 538131a

Please sign in to comment.