Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ansible version #4

Merged
merged 7 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions main.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
- name: Ansible Network Acceessibility Check
hosts: localhost
ignore_errors: true
vars_files:
vars_files:
- port_definition.yaml
tasks:
- name: print var
debug:
debug:
var: port_definitions

- name: Defining fact initialization
include_tasks: "tasks/init_phases.yaml port_definition={{item_port}}"
with_items: "{{port_definitions}}"
include: "tasks/init_phases.yaml"
vars:
port_definition: "{{item_port}}"
with_items: "{{ port_definitions }}"
loop_control:
loop_var: item_port
run_once: true


- name: Testing Ports
include_tasks: "tasks/start_port_check.yaml port_definition={{item_port}}"
include: "tasks/start_port_check.yaml"
vars:
port_definition: "{{item_port}}"
with_items: "{{port_definitions}}"
loop_control:
loop_control:
loop_var: item_port
run_once: true

Expand All @@ -34,4 +38,3 @@
# - name: ensure tmp folder doesnot exist for clean start
# shell: |
# rm -rf /tmp/ansible_network_health_check*

4 changes: 3 additions & 1 deletion tasks/init_phases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
var: port_definition

- name: looping to servers
include_tasks: "loop_phase_to_server.yaml check_to_host={{item_to_host}}"
include: "loop_phase_to_server.yaml"
vars:
check_to_host: "{{item_to_host}}"
with_items: "{{groups[port_definition['to_group']]}}"
loop_control:
loop_var: item_to_host
2 changes: 1 addition & 1 deletion tasks/loop_phase_to_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


- name: loop from clients
include_tasks: tasks/loop_phase_from_clients.yaml
include: tasks/loop_phase_from_clients.yaml
vars:
check_from_host: "{{item_from_host}}"
with_items: "{{groups[port_definition['from_group']]}}"
Expand Down
22 changes: 15 additions & 7 deletions tasks/server_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@
# hosts: ansible_network_health_check_to
# gather_facts: yes
# tasks:
- name: Register result of tests
# when: check_to_host == inventory_hostname
delegate_to: "{{check_to_host}}"
shell: "cat /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_OUTPUT"
register: test_reuslts

- name: Register result of tests
debug:
var: test_reuslts

- name: Check server status
# when: check_to_host == inventory_hostname
delegated_to: "{{check_to_host}}"
with_lines: "cat /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_OUTPUT"
include_tasks: tasks/register_test_result.yaml
vars:
include: tasks/register_test_result.yaml
vars:
test_result_string: "{{item}}"
with_items: "{{test_reuslts.stdout_lines}}"

- name: Ensure no existing process running
delegated_to: "{{check_to_host}}"
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
shell: |
for PIDFILE in $(ls /tmp/ansible_network_health_check_to/*PID); do
Expand All @@ -20,9 +29,8 @@
exit 0

- name: ensure tmp folder doesnot exist for clean start
delegated_to: "{{check_to_host}}"
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
file:
path: /tmp/ansible_network_health_check_to/
state: absent

4 changes: 3 additions & 1 deletion tasks/start_port_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
var: port_definition

- name: start to as server
include_tasks: "start_to_servers.yaml check_to_host={{item_to_host}}"
include: "start_to_servers.yaml"
vars:
check_to_host: "{{item_to_host}}"
with_items: "{{groups[port_definition['to_group']]}}"
loop_control:
loop_var: item_to_host
12 changes: 6 additions & 6 deletions tasks/start_to_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
var: check_to_host

- name: start tcp server
include_tasks: tcp_to_server.yaml
include: tcp_to_server.yaml
when: port_definition['type']|lower == 'tcp'

- name: start udp server
include_tasks: udp_to_server.yaml
include: udp_to_server.yaml
when: port_definition['type']|lower == 'udp'

- name: start from as client - TCP
when: port_definition['type']|lower == 'tcp'
include_tasks: tasks/tcp_from_clients.yaml
include: tasks/tcp_from_clients.yaml
vars:
check_from_host: "{{item_from_host}}"
ansible_network_health_check_port: "{{test_port}}"
Expand All @@ -29,7 +29,7 @@

- name: start from as client - UDP
when: port_definition['type']|lower == 'udp'
include_tasks: tasks/udp_from_clients.yaml
include: tasks/udp_from_clients.yaml
vars:
check_from_host: "{{item_from_host}}"
ansible_network_health_check_port: "{{test_port}}"
Expand All @@ -38,5 +38,5 @@
loop_control:
loop_var: item_from_host

- name: check server result - tcp
include_tasks: tasks/server_check.yaml
- name: check server result - tcp
include: tasks/server_check.yaml
20 changes: 14 additions & 6 deletions tasks/tcp_to_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
kill -9 $(cat /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_PID)
exit 0


- name: ensure tmp folder doesnot exist for clean start
# when: check_to_host == inventory_hostname
delegate_to: "{{check_to_host}}"
file:
file:
path: /tmp/ansible_network_health_check_to/
state: absent

- name: ensure folder exist
- name: ensure folder exist
# when: check_to_host == inventory_hostname
file:
file:
path: /tmp/ansible_network_health_check_to/
state: directory
delegate_to: "{{check_to_host}}"
Expand All @@ -38,7 +37,7 @@
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
shell: |
cd /tmp/ansible_network_health_check_to/
cd /tmp/ansible_network_health_check_to/
python /tmp/ansible_network_health_check_to/tcpServer.py {{test_to_ip}} {{test_port}} /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_OUTPUT &
PID=$!
echo $PID > /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_PID
Expand All @@ -52,10 +51,19 @@
async: 45
poll: 0

- name: register PID of tcpServer.py
delegate_to: "{{check_to_host}}"
shell: "cat /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_PID"
register: PID_tcpServer

- name: debug only
debug:
var: PID_tcpServer

- name: make sure file Exist
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
stat:
path: "/proc/{{lookup('file', '/tmp/ansible_network_health_check_to/'+test_protocol+'_'+test_to_ip+'_'+test_port+'_PID') }}/status"
path: "/proc/{{PID_tcpServer.stdout}}/status"
register: stat_result
failed_when: not stat_result.stat.exists
19 changes: 14 additions & 5 deletions tasks/udp_to_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
- name: ensure tmp folder doesnot exist for clean start
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
file:
file:
path: /tmp/ansible_network_health_check_to/
state: absent

- name: ensure folder exist
- name: ensure folder exist
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
file:
file:
path: /tmp/ansible_network_health_check_to/
state: directory

Expand All @@ -32,7 +32,7 @@
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
shell: |
cd /tmp/ansible_network_health_check_to/
cd /tmp/ansible_network_health_check_to/
python /tmp/ansible_network_health_check_to/udpServer.py {{test_to_ip}} {{test_port}} /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_OUTPUT &
PID=$!
echo $PID > /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_PID
Expand All @@ -46,10 +46,19 @@
async: 45
poll: 0

- name: register PID of udpServer.py
delegate_to: "{{check_to_host}}"
shell: "cat /tmp/ansible_network_health_check_to/{{test_protocol}}_{{test_to_ip}}_{{test_port}}_PID"
register: PID_udpServer

- name: debug only
debug:
var: PID_udpServer

- name: make sure file Exist
delegate_to: "{{check_to_host}}"
# when: check_to_host == inventory_hostname
stat:
path: "/proc/{{lookup('file', '/tmp/ansible_network_health_check_to/'+test_protocol+'_'+test_to_ip+'_'+test_port+'_PID') }}/status"
path: "/proc/{{PID_udpServer.stdout}}/status"
register: stat_result
failed_when: not stat_result.stat.exists