domain.switch.vpn.yml 1.13 KB
---
#  switch vpn 

- hosts: localhost

  vars_prompt:
    - name: "confirmation"
      prompt: "Start to change . Please Enter YES to continue"
      private: no
    - name: "switch_to_where"
      prompt: "Please choose master or slave: [master|slave]"
      default: slave
      private: no

  vars_files:
    - extra_vars/all.yml

  vars:
    qcloud_key: "{{ lookup('hashi_vault',  'secret=yoho/ops/qcloud token='+'{{vault.token}}'+' url='+'{{vault.server}}') }}"

  tasks: 
    - name: "make sure user type YES to confirm"
      fail:
        msg: "user do not type YES"
      when: confirmation != 'YES'

# switch to slave
    - name: domain switch to slave
      domain_modify:
        secretId: "{{ qcloud_key.SecretId }}"
        secretKey: "{{ qcloud_key.SecretKey }}"
        domain_name: "vpn.yoho.cn"
        value: "106.38.39.122"
      when: switch_to_where == 'slave'

# switch to master
    - name: switch to master
      domain_modify:
        secretId: "{{ qcloud_key.SecretId }}"
        secretKey: "{{ qcloud_key.SecretKey }}"
        domain_name: "vpn.yoho.cn"
        value: "218.94.75.58"
      when: switch_to_where == 'master'