--- - name: Agent Server hosts: all gather_facts: false 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 }}" - name: Fetch Agent Details community.mysql.mysql_query: login_host: "{{ nfc_c_mysql_host }}" login_port: "{{ nfc_c_mysql_port | default(3306) | int }}" login_user: "{{ nfc_c_mysql_user }}" login_password: "{{ nfc_c_mysql_password }}" login_db: 'phpipam' query: > SELECT id, code FROM scanAgents WHERE code='{{ inbound_data.code }}' single_transaction: true register: mysql_query_agent_details - name: Confirm Subnet Assignment community.mysql.mysql_query: login_host: "{{ nfc_c_mysql_host }}" login_port: "{{ nfc_c_mysql_port | default(3306) | int }}" login_user: "{{ nfc_c_mysql_user }}" login_password: "{{ nfc_c_mysql_password }}" login_db: 'phpipam' query: > SELECT id, subnet FROM subnets WHERE scanAgent='{{ mysql_query_agent_details.query_result[0][0].id }}' and subnet='{{ (inbound_data.scan.subnet | split('/'))[0] | ip2ipam }}' and mask = '{{ (inbound_data.scan.subnet | split('/'))[1] | int }}' single_transaction: true register: mysql_query_agent_subnets - name: Arrange Subnets ansible.builtin.set_fact: agent_subnets: "{{ agent_subnets | default([]) + [ item.id ] }}" loop: "{{ mysql_query_agent_subnets.query_result[0] }}" - name: Process Scan results ansible.builtin.include_tasks: file: tasks/server/subnet_scan.yaml vars: scan_result: "{{ inbound_data.scan.results }}" vars: ansible_connection: local