switch.askip.yml 1.93 KB
---
# 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:
# 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 }}"