剧本

Updated on in Linux系列 with 0 views and 0 comments

下线 upstream

---
- 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: '\1\2 down weight\3'
      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://solo.cjzshilong.cn/articles/2021/07/01/1625127436405.html

到头来 我们记住的 不是敌人的攻击 而是朋友的沉默 ---马丁·路德·金