feat: initial playbook

This commit is contained in:
Doni Crosby 2025-09-25 19:24:11 -04:00
parent 99bfb97ee7
commit f8e1de4f0a
30 changed files with 1097 additions and 2 deletions

View file

@ -0,0 +1,7 @@
---
# Default variables for docker-install role
docker_compose_version: "2.24.0"
docker_compose_install_path: "/usr/local/bin/docker-compose"
docker_users: []
docker_daemon_config: {}
docker_install_compose: true

View file

@ -0,0 +1,5 @@
---
- name: restart docker
systemd:
name: docker
state: restarted

View file

@ -0,0 +1,19 @@
---
galaxy_info:
author: NetBox Ansible Deployment
description: Installs Docker and Docker Compose on Ubuntu
company: Internal
license: MIT
min_ansible_version: 2.9
platforms:
- name: Ubuntu
versions:
- focal
- jammy
- noble
galaxy_tags:
- docker
- ubuntu
- containers
dependencies: []

View file

@ -0,0 +1,70 @@
---
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
tags:
- docker-install
- gpg-key
- name: Add Docker repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
update_cache: yes
tags:
- docker-install
- repository
- name: Install Docker packages
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
tags:
- docker-install
- packages
- name: Start and enable Docker service
systemd:
name: docker
state: started
enabled: yes
tags:
- docker-install
- service
- name: Add users to docker group
user:
name: "{{ item }}"
groups: docker
append: yes
loop: "{{ docker_users }}"
tags:
- docker-install
- users
- name: Install Docker Compose standalone (if enabled)
get_url:
url: "https://github.com/docker/compose/releases/download/v{{ docker_compose_version }}/docker-compose-linux-x86_64"
dest: "{{ docker_compose_install_path }}"
mode: '0755'
when: docker_install_compose
tags:
- docker-install
- compose
- name: Configure Docker daemon (if config provided)
copy:
content: "{{ docker_daemon_config | to_nice_json }}"
dest: /etc/docker/daemon.json
mode: '0644'
when: docker_daemon_config is defined and docker_daemon_config | length > 0
notify: restart docker
tags:
- docker-install
- daemon-config

View file

@ -0,0 +1,7 @@
---
# Variables for docker-install role
docker_compose_version: "2.24.0"
docker_compose_install_path: "/usr/local/bin/docker-compose"
docker_users: []
docker_daemon_config: {}
docker_install_compose: true

View file

@ -0,0 +1,40 @@
---
# Default variables for netbox-deploy role
netbox_install_dir: "/opt/netbox-docker"
netbox_repo_url: "https://github.com/netbox-community/netbox-docker.git"
netbox_repo_branch: "release"
netbox_repo_update: true
netbox_backup_dir: "/opt/netbox-backups"
netbox_data_dir: "/opt/netbox-data"
# NetBox configuration
netbox_superuser_name: "admin"
netbox_superuser_email: "admin@example.com"
netbox_superuser_password: "admin"
netbox_secret_key: ""
# Database configuration
netbox_db_host: "db"
netbox_db_name: "netbox"
netbox_db_user: "netbox"
netbox_db_password: "netbox"
netbox_db_port: "5432"
# Redis configuration
netbox_redis_host: "redis"
netbox_redis_port: "6379"
netbox_redis_password: ""
# NetBox settings
netbox_allowed_hosts: "localhost,127.0.0.1"
netbox_time_zone: "UTC"
netbox_language_code: "en"
netbox_debug: false
netbox_log_level: "INFO"
# Docker Compose overrides
netbox_docker_compose_overrides:
services:
netbox:
ports:
- "8000:8080"

View file

@ -0,0 +1,19 @@
---
galaxy_info:
author: NetBox Ansible Deployment
description: Deploys NetBox using Docker Compose
company: Internal
license: MIT
min_ansible_version: 2.9
platforms:
- name: Ubuntu
versions:
- focal
- jammy
- noble
galaxy_tags:
- netbox
- docker
- deployment
dependencies: []

View file

@ -0,0 +1,144 @@
---
- name: Create NetBox installation directory
file:
path: "{{ netbox_install_dir }}"
state: directory
owner: root
group: root
mode: '0755'
tags:
- netbox-deploy
- directories
- name: Create NetBox data directory
file:
path: "{{ netbox_data_dir }}"
state: directory
owner: root
group: root
mode: '0755'
tags:
- netbox-deploy
- directories
- name: Create NetBox backup directory
file:
path: "{{ netbox_backup_dir }}"
state: directory
owner: root
group: root
mode: '0755'
tags:
- netbox-deploy
- directories
- name: Clone NetBox Docker repository
git:
repo: "{{ netbox_repo_url }}"
dest: "{{ netbox_install_dir }}"
version: "{{ netbox_repo_branch }}"
update: "{{ netbox_repo_update }}"
force: yes
tags:
- netbox-deploy
- git-clone
- name: Generate NetBox secret key
set_fact:
netbox_secret_key: "{{ netbox_secret_key | default(128 | random_string) }}"
when: netbox_secret_key == ""
tags:
- netbox-deploy
- config
- name: Create NetBox environment file
template:
src: netbox.env.j2
dest: "{{ netbox_install_dir }}/env/netbox.env"
mode: '0644'
tags:
- netbox-deploy
- config
- name: Create PostgreSQL environment file
template:
src: postgres.env.j2
dest: "{{ netbox_install_dir }}/env/postgres.env"
mode: '0644'
tags:
- netbox-deploy
- config
- name: Create Redis environment file
template:
src: redis.env.j2
dest: "{{ netbox_install_dir }}/env/redis.env"
mode: '0644'
tags:
- netbox-deploy
- config
- name: Create Redis Cache environment file
template:
src: redis-cache.env.j2
dest: "{{ netbox_install_dir }}/env/redis-cache.env"
mode: '0644'
tags:
- netbox-deploy
- config
- name: Create Docker Compose override file
template:
src: docker-compose.override.yml.j2
dest: "{{ netbox_install_dir }}/docker-compose.override.yml"
mode: '0644'
tags:
- netbox-deploy
- config
- name: Pull Docker images
docker_compose:
project_src: "{{ netbox_install_dir }}"
pull: yes
tags:
- netbox-deploy
- docker-pull
- name: Start NetBox services
docker_compose:
project_src: "{{ netbox_install_dir }}"
state: present
tags:
- netbox-deploy
- docker-start
- name: Wait for NetBox to be ready
uri:
url: "http://localhost:8000/"
method: GET
status_code: 200
register: netbox_ready
until: netbox_ready.status == 200
retries: 30
delay: 10
tags:
- netbox-deploy
- health-check
- name: Create NetBox superuser
docker_compose:
project_src: "{{ netbox_install_dir }}"
command: "netbox /opt/netbox/netbox/manage.py createsuperuser --noinput --username {{ netbox_superuser_name }} --email {{ netbox_superuser_email }}"
register: superuser_result
failed_when: superuser_result.rc != 0 and "already exists" not in superuser_result.stderr
tags:
- netbox-deploy
- superuser
- name: Set NetBox superuser password
docker_compose:
project_src: "{{ netbox_install_dir }}"
command: "netbox /opt/netbox/netbox/manage.py shell -c \"from django.contrib.auth import get_user_model; User = get_user_model(); u = User.objects.get(username='{{ netbox_superuser_name }}'); u.set_password('{{ netbox_superuser_password }}'); u.save()\""
tags:
- netbox-deploy
- superuser

View file

@ -0,0 +1,4 @@
# Docker Compose Override Configuration
# Generated by Ansible - DO NOT EDIT MANUALLY
{{ netbox_docker_compose_overrides | to_nice_yaml }}

View file

@ -0,0 +1,43 @@
# NetBox Configuration
# Generated by Ansible - DO NOT EDIT MANUALLY
# Database Configuration
DB_HOST={{ netbox_db_host }}
DB_NAME={{ netbox_db_name }}
DB_USER={{ netbox_db_user }}
DB_PASSWORD={{ netbox_db_password }}
DB_PORT={{ netbox_db_port }}
# Redis Configuration (Main Redis)
REDIS_HOST={{ netbox_redis_host }}
REDIS_PORT={{ netbox_redis_port }}
{% if netbox_redis_password %}
REDIS_PASSWORD={{ netbox_redis_password }}
{% endif %}
# Redis Cache Configuration
REDIS_CACHE_HOST={{ netbox_redis_cache_host }}
REDIS_CACHE_PORT={{ netbox_redis_cache_port }}
{% if netbox_redis_cache_password %}
REDIS_CACHE_PASSWORD={{ netbox_redis_cache_password }}
{% endif %}
# NetBox Settings
SECRET_KEY={{ netbox_secret_key }}
ALLOWED_HOSTS={{ netbox_allowed_hosts }}
TIME_ZONE={{ netbox_time_zone }}
LANGUAGE_CODE={{ netbox_language_code }}
DEBUG={{ netbox_debug | lower }}
LOG_LEVEL={{ netbox_log_level }}
# Superuser Configuration
SUPERUSER_NAME={{ netbox_superuser_name }}
SUPERUSER_EMAIL={{ netbox_superuser_email }}
SUPERUSER_PASSWORD={{ netbox_superuser_password }}
# Additional NetBox Configuration
{% if netbox_additional_env is defined %}
{% for key, value in netbox_additional_env.items() %}
{{ key }}={{ value }}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,14 @@
# PostgreSQL Configuration
# Generated by Ansible - DO NOT EDIT MANUALLY
POSTGRES_DB={{ netbox_db_name }}
POSTGRES_USER={{ netbox_db_user }}
POSTGRES_PASSWORD={{ netbox_db_password }}
POSTGRES_PORT={{ netbox_db_port }}
# Additional PostgreSQL Configuration
{% if netbox_postgres_additional_env is defined %}
{% for key, value in netbox_postgres_additional_env.items() %}
{{ key }}={{ value }}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,13 @@
# Redis Cache Configuration
# Generated by Ansible - DO NOT EDIT MANUALLY
{% if netbox_redis_cache_password %}
REDIS_PASSWORD={{ netbox_redis_cache_password }}
{% endif %}
# Additional Redis Cache Configuration
{% if netbox_redis_cache_additional_env is defined %}
{% for key, value in netbox_redis_cache_additional_env.items() %}
{{ key }}={{ value }}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,13 @@
# Redis Configuration (Main Redis)
# Generated by Ansible - DO NOT EDIT MANUALLY
{% if netbox_redis_password %}
REDIS_PASSWORD={{ netbox_redis_password }}
{% endif %}
# Additional Redis Configuration
{% if netbox_redis_additional_env is defined %}
{% for key, value in netbox_redis_additional_env.items() %}
{{ key }}={{ value }}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,8 @@
---
# Variables for netbox-deploy role
netbox_install_dir: "/opt/netbox-docker"
netbox_repo_url: "https://github.com/netbox-community/netbox-docker.git"
netbox_repo_branch: "release"
netbox_repo_update: true
netbox_backup_dir: "/opt/netbox-backups"
netbox_data_dir: "/opt/netbox-data"

View file

@ -0,0 +1,12 @@
---
# Default variables for system-update role
system_update_packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
- software-properties-common
system_update_reboot_if_needed: false
system_update_autoremove: true

View file

@ -0,0 +1,19 @@
---
galaxy_info:
author: NetBox Ansible Deployment
description: Updates Ubuntu system packages
company: Internal
license: MIT
min_ansible_version: 2.9
platforms:
- name: Ubuntu
versions:
- focal
- jammy
- noble
galaxy_tags:
- system
- ubuntu
- updates
dependencies: []

View file

@ -0,0 +1,47 @@
---
- name: Update apt package cache
apt:
update_cache: yes
cache_valid_time: 3600
tags:
- system-update
- apt-update
- name: Upgrade all packages
apt:
upgrade: dist
autoremove: "{{ system_update_autoremove }}"
register: apt_upgrade_result
tags:
- system-update
- apt-upgrade
- name: Install required packages
apt:
name: "{{ system_update_packages }}"
state: present
tags:
- system-update
- packages
- name: Check if reboot is required
stat:
path: /var/run/reboot-required
register: reboot_required
tags:
- system-update
- reboot-check
- name: Reboot if required and enabled
reboot:
msg: "Reboot initiated by Ansible for system updates"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
when:
- reboot_required.stat.exists
- system_update_reboot_if_needed
tags:
- system-update
- reboot

View file

@ -0,0 +1,9 @@
---
# Variables for system-update role
system_update_packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
- software-properties-common