feat(server): move config of variables to vars file

!8 #11
This commit is contained in:
2024-02-23 15:14:56 +09:30
parent de7752cfcf
commit 7df863416e
8 changed files with 45 additions and 41 deletions

View File

@ -19,10 +19,6 @@ Launching the docker container can be done with
docker run \ docker run \
-d \ -d \
-e "API_URL=<your value here>" \
-e "MYSQL_HOST=<your value here>" \
-e "MYSQL_USER=<your value here>" \
-e "MYSQL_PASSWORD=<your value here>" \
-p "5000:5000" \ -p "5000:5000" \
--name scan-agent \ --name scan-agent \
nofusscomputing/phpipam-scan-agent:latest; nofusscomputing/phpipam-scan-agent:latest;
@ -45,6 +41,8 @@ You will need to configure the scan components:
- scanner config file at path `/etc/phpipam/scan_agent.yaml`, see [scanner docs](scanner.md#variables) for details. - scanner config file at path `/etc/phpipam/scan_agent.yaml`, see [scanner docs](scanner.md#variables) for details.
- server config at path `/etc/phpipam/scan_server.yaml`, see [server docs](server.md#variables) for details.
If you wish to customize the cronjob for the scan component within the container, mount a new cron file to path `/etc/cron.d/scanner`. The default cron file is as follows: If you wish to customize the cronjob for the scan component within the container, mount a new cron file to path `/etc/cron.d/scanner`. The default cron file is as follows:
``` yaml title="/etc/cron.d/scanner" linenums="1" ``` yaml title="/etc/cron.d/scanner" linenums="1"

View File

@ -22,24 +22,26 @@ ansible-rulebook -r nofusscomputing.phpipam_scan_agent.agent_receive
### Variables ### Variables
The variables described below, if optional the value specified here is the default value. All variables that are used by the server component are environmental variables that must be set before execution. Ansbible variable name is enclused in `[]` The variables described below, if optional the value specified here is the default value. The variables are to be set in a variables file at path `/etc/phpipam/scan_server.yaml`
``` bash ``` yaml
# phpIPAM MariaDB/MySQL Variables nofusscomputing_phpipam_scan_server:
MYSQL_HOST= # Mandatory, String. IP/DNS of host to connect. [nfc_c_mysql_host]
MYSQL_PORT=3306 # Optional, Integer. port to use for connection. [nfc_c_mysql_port] # phpIPAM MariaDB/MySQL Variables
MYSQL_USER= # Mandatory, String. User to authenticate with. [nfc_c_mysql_user] mysql_host: # Mandatory, String. IP/DNS of host to connect. [nfc_c_]
MYSQL_PASSWORD= # Mandatory, String. Password for the user to connect with. [nfc_c_mysql_password] mysql_port: 3306 # Optional, Integer. port to use for connection. [nfc_c_]
mysql_user: # Mandatory, String. User to authenticate with. [nfc_c_]
mysql_password: # Mandatory, String. Password for the user to connect with. [nfc_c_]
# Server Component Variables # Server Component Variables
HTTP_PORT=5000 # Optional, Integer. The port for the Server component to listen for connections. http_port: 5000 # Optional, Integer. The port for the Server component to listen for connections.
``` ```
# Workflow ## Workflow
The Server componet has the following workflow: The Server componet has the following workflow:

View File

@ -6,7 +6,7 @@
- name: Webhook - name: Webhook
ansible.eda.webhook: ansible.eda.webhook:
host: 0.0.0.0 host: 0.0.0.0
port: "{{ HTTP_PORT }}" port: "{{ nofusscomputing_phpipam_scan_server.http_port }}"
rules: rules:

View File

@ -0,0 +1,13 @@
---
nofusscomputing_phpipam_scan_server:
# phpIPAM MariaDB/MySQL Variables
# mysql_host: # Mandatory, String. IP/DNS of host to connect. [nfc_c_]
# mysql_port: 3306 # Optional, Integer. port to use for connection. [nfc_c_]
# mysql_user: # Mandatory, String. User to authenticate with. [nfc_c_]
# mysql_password: # Mandatory, String. Password for the user to connect with. [nfc_c_]
# Server Component Variables
# http_port: 5000 # Optional, Integer. The port for the Server component to listen for connections.

View File

@ -1,7 +1,7 @@
[program:rulebook] [program:rulebook]
startsecs=0 startsecs=0
stopwaitsecs=55 stopwaitsecs=55
command=ansible-rulebook -r nofusscomputing.phpipam_scan_agent.agent_receive --env-vars "HTTP_PORT" -i /root/hosts.yaml -v command=ansible-rulebook -r nofusscomputing.phpipam_scan_agent.agent_receive --vars /etc/phpipam/scan_server.yaml -i /root/hosts.yaml -v
autorestart=true autorestart=true
autostart=true autostart=true
stdout_logfile=/dev/fd/1 stdout_logfile=/dev/fd/1

View File

@ -7,15 +7,6 @@
tasks: tasks:
- name: Fetch Required Environmental Variables
ansible.builtin.set_fact:
nfc_c_mysql_host: "{{ lookup('ansible.builtin.env', 'MYSQL_HOST') | default('') }}"
nfc_c_mysql_port: "{{ lookup('ansible.builtin.env', 'MYSQL_PORT') | default(3306) | int }}"
nfc_c_mysql_user: "{{ lookup('ansible.builtin.env', 'MYSQL_USER') | default('') }}"
nfc_c_mysql_password: "{{ lookup('ansible.builtin.env', 'MYSQL_PASSWORD') | default('') }}"
no_log: true
- name: TRACE Inbound data Received - name: TRACE Inbound data Received
ansible.builtin.debug: ansible.builtin.debug:
msg: "{{ inbound_data }}" msg: "{{ inbound_data }}"
@ -23,10 +14,10 @@
- name: Fetch Agent Details - name: Fetch Agent Details
community.mysql.mysql_query: community.mysql.mysql_query:
login_host: "{{ nfc_c_mysql_host }}" login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}"
login_port: "{{ nfc_c_mysql_port | default(3306) | int }}" login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}"
login_user: "{{ nfc_c_mysql_user }}" login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}"
login_password: "{{ nfc_c_mysql_password }}" login_password: "{{ nofusscomputing_phpipam_scan_server.mysql_password }}"
login_db: 'phpipam' login_db: 'phpipam'
query: > query: >
@ -37,10 +28,10 @@
- name: Confirm Subnet Assignment - name: Confirm Subnet Assignment
community.mysql.mysql_query: community.mysql.mysql_query:
login_host: "{{ nfc_c_mysql_host }}" login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}"
login_port: "{{ nfc_c_mysql_port | default(3306) | int }}" login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}"
login_user: "{{ nfc_c_mysql_user }}" login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}"
login_password: "{{ nfc_c_mysql_password }}" login_password: "{{ nofusscomputing_phpipam_scan_server.mysql_password }}"
login_db: 'phpipam' login_db: 'phpipam'
query: > query: >

View File

@ -3,10 +3,10 @@
- name: "Update IP Address' found - {{ scan_address.ipaddress.ip }}" - name: "Update IP Address' found - {{ scan_address.ipaddress.ip }}"
community.mysql.mysql_query: community.mysql.mysql_query:
login_host: "{{ nfc_c_mysql_host }}" login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}"
login_port: "{{ nfc_c_mysql_port | default(3306) | int }}" login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}"
login_user: "{{ nfc_c_mysql_user }}" login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}"
login_password: "{{ nfc_c_mysql_password }}" login_password: "{{ nofusscomputing_phpipam_scan_server.mysql_password }}"
login_db: 'phpipam' login_db: 'phpipam'
query: |- query: |-

View File

@ -3,10 +3,10 @@
- name: Match Scan Addresses to DB Details - name: Match Scan Addresses to DB Details
community.mysql.mysql_query: community.mysql.mysql_query:
login_host: "{{ nfc_c_mysql_host }}" login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}"
login_port: "{{ nfc_c_mysql_port | default(3306) | int }}" login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}"
login_user: "{{ nfc_c_mysql_user }}" login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}"
login_password: "{{ nfc_c_mysql_password }}" login_password: "{{ nofusscomputing_phpipam_scan_server.mysql_password }}"
login_db: 'phpipam' login_db: 'phpipam'
query: |- query: |-