aboutsummaryrefslogtreecommitdiff
path: root/roles/netbox/tasks/main.yaml
blob: 9238cc04781696bd5319d20e076c33f20774b41f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
- name: Install packages
  apt:
    name:
      - redis-server
      - python3
      - python3-pip
      - python3-venv
      - python3-dev
      - build-essential
      - libxml2-dev
      - libxslt1-dev
      - libffi-dev
      - libpq-dev
      - libssl-dev
      - zlib1g-dev
      # LDAP
      - libldap2-dev
      - libsasl2-dev
      - libssl-dev
  become: true

- name: Create User
  user:
    name: netbox
    system: true
  become: true

- name: Create folder
  file:
    path: /opt/netbox_data
    owner: netbox
    state: directory
  become: true

- name: Generate SECRET_KEY
  command:
    cmd: 'bash -c "dd if=/dev/urandom bs=1 count=50 status=none | base64"'
    creates: /opt/netbox_data/secret_key
  become_user: netbox
  become: true
  register: gen_sec_key

- name: Save secret Key
  copy:
    content: '{{ gen_sec_key.stdout }}'
    dest: /opt/netbox_data/secret_key
    owner: root
    group: netbox
    mode: '640'
  become: true
  when: gen_sec_key.changed

- name: Read secret Key
  slurp:
    src: /opt/netbox_data/secret_key
  become: true
  register: sec_key

- name: Install PostgreSQL
  include_tasks: postgres.yaml
  when: netbox_local_postgres

- name: Download netbox
  get_url:
    url: 'https://github.com/netbox-community/netbox/archive/refs/tags/v{{ netbox_version }}.tar.gz'
    dest: '/opt/netbox_data/netbox_{{ netbox_version }}.tar.gz'
  become: true
  become_user: netbox
  register: archive_download
  notify:
    - Handle systemd

- name: Unpack netbox
  unarchive:
    src: '/opt/netbox_data/netbox_{{ netbox_version }}.tar.gz'
    remote_src: true
    dest: '/opt/netbox_data/'
  become: true
  become_user: netbox
  when: archive_download.changed

- name: create link to right version
  file:
    state: link
    path: /opt/netbox
    src: '/opt/netbox_data/netbox-{{ netbox_version }}'
  become: true

- name: Create the configuration
  template:
    src: configuration.py.j2
    dest: /opt/netbox/netbox/netbox/configuration.py
    owner: netbox
  become: true
  notify:
    - Handle systemd

- name: Add LDAP dependencies to requirements.txt
  copy:
    content: 'django-auth-ldap'
    dest: /opt/netbox/local_requirements.txt
    owner: netbox
  become: true

- name: Install LDAP Configuration
  copy:
    dest: /opt/netbox/netbox/netbox/ldap_config.py
    content: '{{ ldap_config }}'
    owner: netbox
  become: true
  when: ldap_enable
  notify:
    - Handle systemd

- name: Install Gunicorn Configuration file
  template:
    src: gunicorn.py.j2
    dest: '/opt/netbox/gunicorn.py'
    owner: netbox
  become: true
  notify:
    - Handle systemd

- name: Install Gunicorn Unit files
  copy:
    remote_src: true
    src: '/opt/netbox/contrib/{{ item }}'
    dest: '/etc/systemd/system/{{ item }}'
  become: true
  loop:
    - netbox-housekeeping.service
    - netbox-rq.service
    - netbox.service
    - netbox-housekeeping.timer
  notify:
    - Handle systemd
    - Daemon reload
    - Enable units

- name: Run the upgrade script
  command:
    cmd: /opt/netbox/upgrade.sh
  become: true
  become_user: netbox
  when: archive_download.changed