Added Ansible playbooks
This commit is contained in:
parent
b1c16a00ff
commit
2ca06e8cc6
|
@ -0,0 +1,93 @@
|
|||
- name: Install Broadcast
|
||||
hosts: Lothlorien
|
||||
tasks:
|
||||
- name: Create Broadcast bedroom speaker audio Docker volume directory
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: /data/broadcast-bedroom-speaker-audio
|
||||
state: directory
|
||||
- name: Create Broadcast bedroom speaker audio Docker volume
|
||||
community.docker.docker_volume:
|
||||
volume_name: broadcast-bedroom-speaker-audio
|
||||
driver: local
|
||||
driver_options:
|
||||
type: none
|
||||
o: bind
|
||||
device: /data/broadcast-bedroom-speaker-audio
|
||||
|
||||
- name: Create temporary Docker build directory for broadcast-player
|
||||
ansible.builtin.tempfile:
|
||||
state: directory
|
||||
register: docker_build_dir
|
||||
- name: Copy Docker build directory
|
||||
ansible.builtin.copy:
|
||||
src: player/
|
||||
dest: '{{docker_build_dir.path}}'
|
||||
mode: preserve
|
||||
- name: Build broadcast-player Docker image
|
||||
ansible.builtin.docker_image:
|
||||
build:
|
||||
path: '{{docker_build_dir.path}}'
|
||||
name: broadcast-player
|
||||
tag: latest
|
||||
source: build
|
||||
force_source: true
|
||||
state: present
|
||||
- name: Remove temporary Docker build directory
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: '{{docker_build_dir.path}}'
|
||||
state: absent
|
||||
|
||||
- name: Read homelab config
|
||||
ansible.builtin.slurp:
|
||||
src: '{{ansible_user_dir}}/.homelab.json'
|
||||
register: homelab_config_file
|
||||
- name: Set homelab_config variable
|
||||
ansible.builtin.set_fact:
|
||||
homelab_config: '{{homelab_config_file.content|b64decode|from_json}}'
|
||||
|
||||
- name: Insert into Postgres table service
|
||||
community.postgresql.postgresql_query:
|
||||
login_host: '{{homelab_config.database.host}}'
|
||||
login_user: '{{homelab_config.database.user}}'
|
||||
login_password: '{{homelab_config.database.password}}'
|
||||
db: '{{homelab_config.database.name}}'
|
||||
query: 'INSERT INTO service (name, host, source, config) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING;'
|
||||
positional_args:
|
||||
- '{{item.name}}'
|
||||
- '{{item.host}}'
|
||||
- '{{item.source}}'
|
||||
- '{{item.config}}'
|
||||
with_items:
|
||||
- {name: broadcast, host: '{{ansible_hostname}}', source: gitea/ashish/broadcast/master, config: null}
|
||||
- name: Insert into Postgres table service_port
|
||||
community.postgresql.postgresql_query:
|
||||
login_host: '{{homelab_config.database.host}}'
|
||||
login_user: '{{homelab_config.database.user}}'
|
||||
login_password: '{{homelab_config.database.password}}'
|
||||
db: '{{homelab_config.database.name}}'
|
||||
query: 'INSERT INTO service_port (service, port, domain, reverse_proxy, reverse_proxy_port) VALUES (%s, %s, %s, %s, %s) ON CONFLICT DO NOTHING;'
|
||||
positional_args:
|
||||
- '{{item.service}}'
|
||||
- '{{item.port}}'
|
||||
- '{{item.domain}}'
|
||||
- '{{item.reverse_proxy}}'
|
||||
- '{{item.reverse_proxy_port}}'
|
||||
with_items:
|
||||
- {service: broadcast, port: 10000, domain: null, reverse_proxy: null, reverse_proxy_port: null}
|
||||
- {service: broadcast, port: 10001, domain: null, reverse_proxy: null, reverse_proxy_port: null}
|
||||
- name: Insert into Postgres table service_data
|
||||
community.postgresql.postgresql_query:
|
||||
login_host: '{{homelab_config.database.host}}'
|
||||
login_user: '{{homelab_config.database.user}}'
|
||||
login_password: '{{homelab_config.database.password}}'
|
||||
db: '{{homelab_config.database.name}}'
|
||||
query: 'INSERT INTO service_data (service, data_name, storage_type, source) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING;'
|
||||
positional_args:
|
||||
- '{{item.service}}'
|
||||
- '{{item.data_name}}'
|
||||
- '{{item.storage_type}}'
|
||||
- '{{item.source}}'
|
||||
with_items:
|
||||
- {service: broadcast, data_name: bedroom_speaker_audio, storage_type: docker, source: broadcast-bedroom-speaker-audio}
|
|
@ -0,0 +1,25 @@
|
|||
- name: Start Broadcast
|
||||
hosts: Lothlorien
|
||||
tasks:
|
||||
- name: Create temporary Docker Compose directory
|
||||
ansible.builtin.tempfile:
|
||||
state: directory
|
||||
register: docker_compose_dir
|
||||
- name: Copy docker-compose.yaml
|
||||
ansible.builtin.copy:
|
||||
src: conf/docker-compose.yaml
|
||||
dest: '{{docker_compose_dir.path}}/docker-compose.yaml'
|
||||
mode: preserve
|
||||
|
||||
- name: Docker Compose up Broadcast
|
||||
environment:
|
||||
SERVER_IP: '{{ansible_default_ipv4.address}}'
|
||||
community.docker.docker_compose:
|
||||
project_name: broadcast
|
||||
project_src: '{{docker_compose_dir.path}}'
|
||||
state: present
|
||||
|
||||
- name: Remove temporary Docker Compose directory
|
||||
ansible.builtin.file:
|
||||
path: '{{docker_compose_dir.path}}'
|
||||
state: absent
|
|
@ -0,0 +1,23 @@
|
|||
- name: Stop Broadcast
|
||||
hosts: Lothlorien
|
||||
tasks:
|
||||
- name: Create temporary Docker Compose directory
|
||||
ansible.builtin.tempfile:
|
||||
state: directory
|
||||
register: docker_compose_dir
|
||||
- name: Copy docker-compose.yaml
|
||||
ansible.builtin.copy:
|
||||
src: conf/docker-compose.yaml
|
||||
dest: '{{docker_compose_dir.path}}/docker-compose.yaml'
|
||||
mode: preserve
|
||||
|
||||
- name: Docker Compose down Broadcast
|
||||
community.docker.docker_compose:
|
||||
project_name: broadcast
|
||||
project_src: '{{docker_compose_dir.path}}'
|
||||
state: absent
|
||||
|
||||
- name: Remove temporary Docker Compose directory
|
||||
ansible.builtin.file:
|
||||
path: '{{docker_compose_dir.path}}'
|
||||
state: absent
|
|
@ -0,0 +1,51 @@
|
|||
- name: Stop Broadcast
|
||||
ansible.builtin.import_playbook: stop.yaml
|
||||
|
||||
- name: Uninstall Broadcast
|
||||
hosts: Lothlorien
|
||||
tasks:
|
||||
- name: Remove Broadcast bedroom speaker audio Docker volume
|
||||
community.docker.docker_volume:
|
||||
volume_name: broadcast-bedroom-speaker-audio
|
||||
state: absent
|
||||
- name: Remove Broadcast bedroom speaker audio Docker volume
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: /data/broadcast-bedroom-speaker-audio
|
||||
state: absent
|
||||
|
||||
- name: Read homelab config
|
||||
ansible.builtin.slurp:
|
||||
src: '{{ansible_user_dir}}/.homelab.json'
|
||||
register: homelab_config_file
|
||||
- name: Set homelab_config variable
|
||||
ansible.builtin.set_fact:
|
||||
homelab_config: '{{homelab_config_file.content|b64decode|from_json}}'
|
||||
|
||||
- name: Delete from Postgres table service_data
|
||||
community.postgresql.postgresql_query:
|
||||
login_host: '{{homelab_config.database.host}}'
|
||||
login_user: '{{homelab_config.database.user}}'
|
||||
login_password: '{{homelab_config.database.password}}'
|
||||
db: '{{homelab_config.database.name}}'
|
||||
query: 'DELETE FROM service_data WHERE service = %s;'
|
||||
positional_args:
|
||||
- broadcast
|
||||
- name: Delete from Postgres table service_port
|
||||
community.postgresql.postgresql_query:
|
||||
login_host: '{{homelab_config.database.host}}'
|
||||
login_user: '{{homelab_config.database.user}}'
|
||||
login_password: '{{homelab_config.database.password}}'
|
||||
db: '{{homelab_config.database.name}}'
|
||||
query: 'DELETE FROM service_port WHERE service = %s;'
|
||||
positional_args:
|
||||
- broadcast
|
||||
- name: Delete from Postgres table service
|
||||
community.postgresql.postgresql_query:
|
||||
login_host: '{{homelab_config.database.host}}'
|
||||
login_user: '{{homelab_config.database.user}}'
|
||||
login_password: '{{homelab_config.database.password}}'
|
||||
db: '{{homelab_config.database.name}}'
|
||||
query: 'DELETE FROM service WHERE name = %s;'
|
||||
positional_args:
|
||||
- broadcast
|
Loading…
Reference in New Issue