feat: initial playbook
This commit is contained in:
parent
99bfb97ee7
commit
f8e1de4f0a
30 changed files with 1097 additions and 2 deletions
69
playbooks/backup-netbox.yml
Normal file
69
playbooks/backup-netbox.yml
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
---
|
||||
- name: Backup NetBox Data
|
||||
hosts: netbox
|
||||
become: yes
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: Create backup directory with timestamp
|
||||
file:
|
||||
path: "{{ netbox_backup_dir }}/{{ ansible_date_time.iso8601_basic_short }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
register: backup_dir
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Backup PostgreSQL database
|
||||
docker_compose:
|
||||
project_src: "{{ netbox_install_dir }}"
|
||||
command: "db pg_dump -U {{ netbox_db_user }} {{ netbox_db_name }}"
|
||||
register: db_backup
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Save database backup to file
|
||||
copy:
|
||||
content: "{{ db_backup.stdout }}"
|
||||
dest: "{{ backup_dir.path }}/netbox_db_backup.sql"
|
||||
mode: '0644'
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Backup Redis data
|
||||
archive:
|
||||
path: "{{ netbox_data_dir }}/redis"
|
||||
dest: "{{ backup_dir.path }}/redis-data.tar.gz"
|
||||
format: gz
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Backup Redis Cache data
|
||||
archive:
|
||||
path: "{{ netbox_data_dir }}/redis-cache"
|
||||
dest: "{{ backup_dir.path }}/redis-cache-data.tar.gz"
|
||||
format: gz
|
||||
ignore_errors: yes
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Backup Docker Compose configuration
|
||||
copy:
|
||||
src: "{{ netbox_install_dir }}/"
|
||||
dest: "{{ backup_dir.path }}/docker-compose-config/"
|
||||
mode: '0644'
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Display backup information
|
||||
debug:
|
||||
msg:
|
||||
- "Backup completed successfully!"
|
||||
- "Backup location: {{ backup_dir.path }}"
|
||||
- "Database backup: {{ backup_dir.path }}/netbox_db_backup.sql"
|
||||
- "Redis data backup: {{ backup_dir.path }}/redis-data.tar.gz"
|
||||
- "Redis Cache data backup: {{ backup_dir.path }}/redis-cache-data.tar.gz"
|
||||
- "Config backup: {{ backup_dir.path }}/docker-compose-config/"
|
||||
tags:
|
||||
- backup
|
||||
67
playbooks/deploy-netbox.yml
Normal file
67
playbooks/deploy-netbox.yml
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
---
|
||||
- name: Deploy NetBox with Docker Compose
|
||||
hosts: netbox
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
pre_tasks:
|
||||
- name: Verify Ubuntu distribution
|
||||
fail:
|
||||
msg: "This playbook only supports Ubuntu distributions"
|
||||
when: ansible_distribution != "Ubuntu"
|
||||
tags: always
|
||||
|
||||
- name: Display deployment information
|
||||
debug:
|
||||
msg:
|
||||
- "Deploying NetBox to {{ inventory_hostname }}"
|
||||
- "OS: {{ ansible_distribution }} {{ ansible_distribution_version }}"
|
||||
- "Architecture: {{ ansible_architecture }}"
|
||||
- "Installation directory: {{ netbox_install_dir }}"
|
||||
tags: always
|
||||
|
||||
roles:
|
||||
- role: system-update
|
||||
tags:
|
||||
- system-update
|
||||
- updates
|
||||
- packages
|
||||
|
||||
- role: docker-install
|
||||
tags:
|
||||
- docker-install
|
||||
- docker
|
||||
- containers
|
||||
|
||||
- role: netbox-deploy
|
||||
tags:
|
||||
- netbox-deploy
|
||||
- netbox
|
||||
- application
|
||||
|
||||
post_tasks:
|
||||
- name: Display NetBox access information
|
||||
debug:
|
||||
msg:
|
||||
- "NetBox deployment completed successfully!"
|
||||
- "Access NetBox at: http://{{ ansible_default_ipv4.address }}:8000"
|
||||
- "Default admin credentials:"
|
||||
- " Username: {{ netbox_superuser_name }}"
|
||||
- " Email: {{ netbox_superuser_email }}"
|
||||
- " Password: {{ netbox_superuser_password }}"
|
||||
- "Installation directory: {{ netbox_install_dir }}"
|
||||
- "Data directory: {{ netbox_data_dir }}"
|
||||
tags: always
|
||||
|
||||
- name: Show Docker Compose status
|
||||
command: docker compose ps
|
||||
args:
|
||||
chdir: "{{ netbox_install_dir }}"
|
||||
register: docker_compose_status
|
||||
changed_when: false
|
||||
tags: always
|
||||
|
||||
- name: Display Docker Compose status
|
||||
debug:
|
||||
var: docker_compose_status.stdout_lines
|
||||
tags: always
|
||||
43
playbooks/update-netbox.yml
Normal file
43
playbooks/update-netbox.yml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
- name: Update NetBox Docker Repository
|
||||
hosts: netbox
|
||||
become: yes
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: Update NetBox Docker repository
|
||||
git:
|
||||
repo: "{{ netbox_repo_url }}"
|
||||
dest: "{{ netbox_install_dir }}"
|
||||
version: "{{ netbox_repo_branch }}"
|
||||
update: yes
|
||||
force: yes
|
||||
tags:
|
||||
- update-repo
|
||||
|
||||
- name: Pull latest Docker images
|
||||
docker_compose:
|
||||
project_src: "{{ netbox_install_dir }}"
|
||||
pull: yes
|
||||
tags:
|
||||
- pull-images
|
||||
|
||||
- name: Restart NetBox services
|
||||
docker_compose:
|
||||
project_src: "{{ netbox_install_dir }}"
|
||||
state: present
|
||||
recreate: yes
|
||||
tags:
|
||||
- restart-services
|
||||
|
||||
- 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:
|
||||
- health-check
|
||||
Loading…
Add table
Add a link
Reference in a new issue