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,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"