Authored by jie

Merge branch 'master' into ufo-nginx

---
# switch java
- hosts: localhost
vars_prompt:
- name: "confirmation"
prompt: "Start to change . Please Enter YES to continue"
private: no
- name: "switch_to_where"
prompt: "Please choose java endpoint: [qq|aws]"
default: qq
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 qq
- name: domain switch to qq
domain_modify:
secretId: "{{ qcloud_key.SecretId }}"
secretKey: "{{ qcloud_key.SecretKey }}"
domain_name: "api.yoho.cn,service.yoho.cn,union.yoho.cn,webunion.yohobuy.com"
value: "140.143.217.201"
when: switch_to_where == 'qq'
- name: configure ask ip nginx's cloudType = 1
uri:
url: "http://{{item}}/switchCloud?cloudType=1"
headers:
Host: 'dnsresolver.yohoops.org'
with_items: "{{ask_nginx}}"
when: switch_to_where == 'qq'
# switch to aws
- name: switch to aws
domain_modify:
secretId: "{{ qcloud_key.SecretId }}"
secretKey: "{{ qcloud_key.SecretKey }}"
domain_name: "api.yoho.cn,service.yoho.cn,union.yoho.cn,webunion.yohobuy.com"
value: "java-public-lb-862332839.cn-north-1.elb.amazonaws.com.cn"
when: switch_to_where == 'aws'
- name: configure ask ip nginx's cloudType = 2
uri:
url: "http://{{item}}/switchCloud?cloudType=2"
headers:
Host: 'dnsresolver.yohoops.org'
with_items: "{{ask_nginx}}"
when: switch_to_where == 'aws'
\ No newline at end of file
... ...
... ... @@ -9,6 +9,10 @@ yoho_office_ips:
- 106.38.38.147
- 172.31.0.0/16
ask_nginx:
- 10.66.4.23
- 10.66.4.15
cobar:
user: yh_vpc_bak
password: yoho@2Y$^YpNb7hp
... ...
# Last updated at 2019/01/07 14:30 by tiexin.yang@yoho.cn
# Sync and apply java nginx config file
# How to Run:
# Use the default settings:
# ansible-playbook -i inventories/az1/hosts playbooks/java-nginx.switch_aws.yml
- hosts: java-nginx
pre_tasks:
- shell: cat /proc/cpuinfo | grep processor | wc -l
register: cpu_count_ret
- set_fact:
processor_count: "{{ cpu_count_ret.stdout }}"
when: not ansible_check_mode
vars_prompt:
- name: "confirmation"
prompt: "Sync and reload java nginx. Please Enter YES to continue."
private: no
vars:
java_gateway_ips:
- java-gateway-431f16063270008f.elb.cn-north-1.amazonaws.com.cn
remote_user: root
roles:
- openresty
... ... @@ -18,8 +18,10 @@
- name: "confirmation"
prompt: "Sync and reload java nginx. Please Enter YES to continue."
private: no
vars:
java_gateway_ips: "{{ groups['java-gateway'] }}"
- name: "upstream_az"
prompt: "Choose which az's upstream: [local|az1|aws] "
default: 'local'
private: no
remote_user: root
roles:
- openresty
... ...
... ... @@ -129,9 +129,15 @@ http
#apigatewaystart
upstream apigateway {
{% for i in java_gateway_ips %}
server {{ i }}:8080 max_fails=5 fail_timeout=3s;
{% endfor %}
{% if upstream_az == 'aws' %}
server java-gateway-431f16063270008f.elb.cn-north-1.amazonaws.com.cn:8080 max_fails=5 fail_timeout=3s;
{% elif upstream_az == 'az1'%}
server 10.66.4.112:8080 max_fails=5 fail_timeout=3s;
{% else %}
{% for i in groups['java-gateway'] %}
server {{ i }}:8080 max_fails=5 fail_timeout=3s;
{% endfor %}
{% endif %}
keepalive 32;
}
... ...