ansible-role-netbox/tasks/main.yml

109 lines
2.5 KiB
YAML
Raw Normal View History

2022-07-08 21:51:48 +02:00
- name: Install packages.
tags: netbox
become: true
ansible.builtin.package:
name:
- python3
- python3-pip
- python3-venv
- python3-dev
- build-essential
- libxml2-dev
- libxslt1-dev
- libffi-dev
- libpq-dev
- libssl-dev
- zlib1g-dev
- name: Create service group.
tags: netbox
become: true
ansible.builtin.group:
state: present
name: "{{ netbox_group }}"
system: yes
- name: Create service user.
tags: netbox
become: true
ansible.builtin.user:
state: present
name: "{{ netbox_user }}"
group: "{{ netbox_group }}"
system: yes
- name: Create directory.
become: true
ansible.builtin.file:
path: "{{ netbox_path }}"
state: directory
2022-07-08 23:44:53 +02:00
mode: 0755
2022-07-08 21:51:48 +02:00
owner: "{{ netbox_user }}"
group: "{{ netbox_group }}"
- name: Git checkout.
become: true
become_user: "{{ netbox_user }}"
ansible.builtin.git:
repo: 'https://github.com/netbox-community/netbox.git'
dest: "{{ netbox_path }}"
version: master
depth: 1
register: netbox_git_checkout
- name: Create configuration from template.
become: true
ansible.builtin.template:
src: "configuration.py.j2"
dest: "{{ netbox_path }}/netbox/netbox/configuration.py"
owner: "{{ netbox_user }}"
group: "{{ netbox_user }}"
2022-07-08 23:44:53 +02:00
mode: 0644
2022-07-08 21:51:48 +02:00
- name: Run update script.
become: true
become_user: netbox
ansible.builtin.shell:
cmd: "cd {{ netbox_path }} && /opt/netbox/upgrade.sh"
when: netbox_git_checkout.changed == true
- name: Schedule housekeeping task.
become: true
ansible.builtin.file:
src: "{{ netbox_path }}/contrib/netbox-housekeeping.sh"
dest: /etc/cron.daily/netbox-housekeeping.sh
state: link
- name: Create Gunicorn config.
become: true
ansible.builtin.copy:
remote_src: true
src: "{{ netbox_path }}/contrib/gunicorn.py"
dest: "{{ netbox_path }}/gunicorn.py"
- name: Create systemd services.
become: true
ansible.builtin.copy:
remote_src: true
src: "{{ netbox_path }}/contrib/{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
with_items:
- netbox.service
- netbox-rq.service
- name: Enable systemd services.
become: true
ansible.builtin.systemd:
name: "{{ item }}"
state: started
enabled: true
with_items:
- netbox.service
- netbox-rq.service
- name: Create nginx site.
become: true
ansible.builtin.template:
src: "nginx.conf.j2"
dest: "/etc/nginx/conf.d/netbox.conf"
notify: reload nginx