剧本

2022-06-14 19:46:23 浏览数 (1)

下线 upstream

代码语言:javascript复制
---
- hosts: all
  remote_user: root
  gather_facts: false
  vars:
    upstream_base_path: "/usr/local/openresty/nginx/conf/vhosts"
    inside_upstream_path: "{{upstream_base_path}}/inside-upstream"
    outside_upstream_path: "{{upstream_base_path}}/outside-upstream"
    nginx_bin_path: "/usr/local/openresty/nginx/sbin/nginx"

    domains: "{{ domains }}"
    servers: "{{ servers }}"

  tasks:
  - name: "下线inside_upstream配置"
    ignore_errors: True
    lineinfile:
      path: "{{ inside_upstream_path }}/{{item.1}}.conf"
      regexp: "(.*)(server {{item.0}}) weight(.*)"
      line: '12 down weight3'
      backrefs: yes
    with_nested:
      - "{{ servers.split(',') }}"
      - "{{ domains.split(',') }}"

  - name: "Nginx test"
    command: "{{nginx_bin_path}} -t"

  - name: "Nginx reload"
    command: "{{nginx_bin_path}} -s reload"

ansible-playbook -i /alidata/ops/inventory/jishuzhongtai --extra-vars "{'servers':'172.16.16.51:8090', 'domains':'wiki.limikeji.com'}" test.yml


标题:剧本

作者:cuijianzhe

地址:https://cloud.tencent.com/developer/article/2022891

0 人点赞