From c6b2499b8ec9699a4e02b8cef31a7ac5ce053735 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 21 Feb 2024 00:13:05 +0930 Subject: [PATCH] feat: build required vars from environmental variables !1 --- playbooks/agent.yaml | 53 +++++++++++++++++++++++++++++++++++ playbooks/server.yaml | 9 ++++++ playbooks/tasks/api_call.yaml | 1 + 3 files changed, 63 insertions(+) diff --git a/playbooks/agent.yaml b/playbooks/agent.yaml index f1c1aaa..9a319ed 100644 --- a/playbooks/agent.yaml +++ b/playbooks/agent.yaml @@ -5,6 +5,59 @@ tasks: + + - name: Fetch Required Environmental Variables + ansible.builtin.set_fact: + client_token: "{{ lookup('ansible.builtin.env', 'SCANNER_TOKEN') | default('') }}" + client_name: "{{ lookup('ansible.builtin.env', 'SCANNER_NAME') }}" + scanagent_code: "{{ lookup('ansible.builtin.env', 'SCANNER_CODE') | default('') }}" + api_url: "{{ lookup('ansible.builtin.env', 'API_URL') | default('') }}" + no_log: true + when: > + client_token is not defined + and + client_name is not defined + and + scanagent_code is not defined + and + api_url is not defined + + + - name: Fetch Required Environmental Variables + ansible.builtin.set_fact: + nfc_c_http_server: "{{ lookup('ansible.builtin.env', 'HTTP_URL') | default('') }}" + when: > + lookup('ansible.builtin.env', 'HTTP_URL') | default('') != '' + + + - name: Confirm 'api_url' is Set + ansible.builtin.assert: + that: + - api_url is defined + msg: "missing Required Variables" + + + - name: Confirm 'client_token' is Set + ansible.builtin.assert: + that: + - client_token is defined + msg: "missing Required Variables" + + + - name: Confirm 'client_name' is Set + ansible.builtin.assert: + that: + - client_name is defined + msg: "missing Required Variables" + + + - name: Confirm 'scanagent_code' is Set + ansible.builtin.assert: + that: + - scanagent_code is defined + msg: "missing Required Variables" + + - name: Create API Cache Directory ansible.builtin.file: path: "{{ nfc_c_path_cache }}" diff --git a/playbooks/server.yaml b/playbooks/server.yaml index e28aa87..dc41f9b 100644 --- a/playbooks/server.yaml +++ b/playbooks/server.yaml @@ -7,6 +7,15 @@ 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 ansible.builtin.debug: msg: "{{ inbound_data }}" diff --git a/playbooks/tasks/api_call.yaml b/playbooks/tasks/api_call.yaml index 7039e2a..aac94d6 100644 --- a/playbooks/tasks/api_call.yaml +++ b/playbooks/tasks/api_call.yaml @@ -9,6 +9,7 @@ - api_client_name is defined - api_path is defined - api_token is defined + - api_url is defined - name: API Facts