--- - name: Agent Server hosts: all gather_facts: false tasks: - name: TRACE Inbound data Received ansible.builtin.debug: msg: "{{ inbound_data }}" - name: Check for Existance of config file ansible.builtin.stat: path: /etc/phpipam/scan_server.yaml register: config_file_check - name: Load Config File ansible.builtin.include_vars: file: /etc/phpipam/scan_server.yaml when: > config_file_check.stat.exists - name: Fetch Agent Details community.mysql.mysql_query: login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}" login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}" login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}" login_password: "{{ nofusscomputing_phpipam_scan_server.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: Update Scan Agent Last seen community.mysql.mysql_query: login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}" login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}" login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}" login_password: "{{ nofusscomputing_phpipam_scan_server.mysql_password }}" login_db: 'phpipam' query: |- UPDATE scanAgents SET last_access = '{{ ('%Y-%m-%d %H:%M:%S' | strftime) }}' WHERE id = '{{ mysql_query_agent_details.query_result[0][0].id }}' single_transaction: true - name: Confirm Subnet Assignment community.mysql.mysql_query: login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}" login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}" login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}" login_password: "{{ nofusscomputing_phpipam_scan_server.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