-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_connection_info.yml
64 lines (56 loc) · 2.38 KB
/
get_connection_info.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
- hosts: "localhost"
gather_facts: true
vars:
ip_list:
192.168.178.1
tasks:
- name: Get Current Connection Information
uri:
url: "http://{{ item }}:49000/igdupnp/control/WANCommonIFC1"
method: POST
body_format: json
body: "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:GetStatusInfo xmlns:u='urn:schemas-upnp-org:service:WANIPConnection:1'></u:GetStatusInfo></s:Body></s:Envelope>"
headers:
Content-Type: 'text/xml; charset="utf-8"'
SoapAction: "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetCommonLinkProperties"
force_basic_auth: true
return_content: true
validate_certs: false
register: connection_information_xml
loop:
- "{{ ip_list }}"
- name: Print connection informations
debug:
# var: connection_information
var: connection_information_xml.results[0].content
- name: Get current external IP Address
uri:
url: "http://{{ item }}:49000/igdupnp/control/WANIPConn1"
method: POST
body_format: json
body: "<?xml version='1.0' encoding='utf-8'?><s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/' s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><s:Body><u:GetExternalIPAddress xmlns:'u=urn:schemas-upnp-org:service:WANIPConnection:1'></u:GetExternalIPAddress></s:Body></s:Envelope>"
headers:
Content-Type: 'text/xml; charset="utf-8"'
SoapAction: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"
force_basic_auth: true
return_content: true
validate_certs: false
register: external_ip_xml
loop:
- "{{ ip_list }}"
- name: Convert XML to JSON
xml:
xmlstring: "{{external_ip_xml.results[0].content}}"
xpath: /s:Envelope/s:Body/u:GetExternalIPAddressResponse/NewExternalIPAddress
content: text
namespaces:
s: "http://schemas.xmlsoap.org/soap/envelope/"
u: "urn:schemas-upnp-org:service:WANIPConnection:1"
register: external_ip
- name: Print external IP address
debug:
var: external_ip.matches[0].NewExternalIPAddress
- name: Setting external IP Address as Variable for later use
set_fact:
external_ip_address: "{{ external_ip.matches[0].NewExternalIPAddress }}"