switch.askip.yml
2.07 KB
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
65
66
67
68
69
70
71
72
73
74
---
# modidy ask ip server's configuration
# anthor: chunhua.zhang
- hosts: localhost
vars_prompt:
- name: "confirmation"
prompt: "Start to change . Please Enter YES to continue"
private: no
- name: "netType"
prompt: "Please choose device enterpoint: 0 for Domain(api.yoho.cn) or 1 for DCDN(api-dc1-qq.yoho.cn). [0|1]"
default: 1
private: no
- name: "cloudType"
prompt: "Please choose DCDN enterpoint: 1 for main(api-dc1-qq) or 2 for backup(api-dc2-qq). [1|2]"
default: 1
private: no
tasks:
- name: "make sure user type YES to confirm"
fail:
msg: "user do not type YES"
when: confirmation != 'YES'
# query for current configration
- name: Query for current configuration
uri:
url: "http://{{item}}/queryCloud"
return_content: yes
status_code: 200
body_format: json
headers:
Host: 'dnsresolver.yohoops.org'
register: result
with_items: "{{ groups['askip-nginx'] }}"
- name: print ask ip query results
debug:
msg: "{{ item.json}}"
with_items: "{{ result.results }}"
# do the switch
- name: switch net type
uri:
url: "http://{{item}}/switchCloud?netType={{ netType }}&cloudType={{ cloudType }}"
return_content: yes
status_code: 200
body_format: json
headers:
Host: 'dnsresolver.yohoops.org'
register: switch_result
with_items: "{{ groups['askip-nginx'] }}"
- name: print swith netType results
debug:
msg: "{{ item.json }}"
with_items: "{{ switch_result.results }}"
# make sure switch is enabled
- name: Query for current configuration
uri:
url: "http://{{item}}/queryCloud"
return_content: yes
status_code: 200
body_format: json
headers:
Host: 'dnsresolver.yohoops.org'
register: last_result
with_items: "{{ groups['askip-nginx'] }}"
- name: print ask ip query results
debug:
msg: "{{ item.json}}"
with_items: "{{ last_result.results }}"