• ansible的playbook执行流程分析


    项目架构

             

             

            ansible-playbook  -i  hosts  --tags base  site.yml

             

           ansible-playbook  -i  hosts  --tags base  --skip-tags cluster-uninstall site.yml

           不再执行task/main.yml中标签为cluster-uninstall的task集合

            ansible-playbook --list-tags site.yml

              

      ansible架构实现安装和卸载任务的区分   

    - name: Copy meld3-0.6.5.tar.gz to {{ groups["all"] | to_json }}
      copy: src=../../common/packages/supervisor/meld3-0.6.5.tar.gz dest=/tmp
      tags: supervisor
    
    
    - name: Copy setuptools-24.0.2.tar.gz to {{ groups["all"]  | to_json }}
      copy: src=../../common/packages/supervisor/setuptools-24.0.2.tar.gz dest=/tmp
      tags: supervisor
    
    
    - name: Copy supervisor-3.3.0.tar.gz to {{ groups["all"] | to_json }}
      copy: src=../../common/packages/supervisor/supervisor-3.3.0.tar.gz dest=/tmp
      tags: supervisor
    
    - name: Install setuptools to {{ groups["all"] | to_json }}
      shell: "cd /tmp && tar -zxvf setuptools-24.0.2.tar.gz && cd setuptools-24.0.2/ && python setup.py install"
      tags: supervisor
    
    - name: Install elementtree to {{ groups["all"] | to_json }}
      shell: "cd /tmp && easy_install elementtree-1.2.7-20070827-preview.zip"
      tags: supervisor
    
    - name: Install meld3-0.6.5 to {{ groups["all"] | to_json }}
      shell: "cd /tmp && easy_install meld3-0.6.5.tar.gz"
      tags: supervisor
    
    
    - name: Install supervisor to {{ groups["all"] | to_json }}
      shell: "cd /tmp && easy_install supervisor-3.3.0.tar.gz"
      tags: supervisor
    
    - name:  reload taishiservice to {{ groups["all"] | to_json }}
      shell: "systemctl daemon-reload"
      tags: supervisor
    
    - name:  start taishiservice to {{ groups["all"] | to_json }}
      service: name=taishi state=started
      tags: supervisor
    
    
    - name: "chown taishi dir to {{ taishi_user }}"
      file: path="{{ taishi_dir }}" state=directory owner={{ taishi_user }} group={{ taishi_user }} recurse=yes
      tags: base
    
    # - name: Copy the nodexporter.service to {{ groups["all"]  | to_json }}
    #   template: src=node_exporter.service.j2  dest="/etc/systemd/system/node_exporter.service" owner={{ taishi_user }} group={{ taishi_user }} mode=0755
    #   tags: nodexporter
    
    
    # - name: Copy nodexporter.tar.gz to {{ groups["all"]  | to_json }}
    #   copy: src=node_exporter-1.0.1.linux-amd64.tar.gz dest=/tmp
    #   tags: nodexporter
    
    
    # - name: Install nodexporter for {{ groups["all"]  | to_json }}
    #   unarchive: src="/tmp/node_exporter-1.0.1.linux-amd64.tar.gz" dest="/usr/local/bin/node_exporter"  copy=no mode=0755 owner={{ taishi_user }} group={{ taishi_user }}
    #   tags: nodexporter
    
    - name: "get all nodes status"
      shell: "supervisorctl status"
      register: result
      tags: checknodes
    
    - name: "show all node status"
      debug:
        msg: "{{ result }}"
      tags: checknodes
    
    
    - name: "stop taishi serivice"
      service: name=taishi state=stopped
      tags: uninstall,cluster-uninstall
    
    - name: "delete cluster directory"
      file: path="{{ taishi_dir }}" state=absent
      tags: uninstall,cluster-uninstall
    
    
    - name: "delete zk_dataDir directory"
      file: path="{{ zk_dataDir }}" state=absent
      ignore_errors: True
      tags: uninstall,cluster-uninstall
    
    - name: "delete zk_logDir directory"
      file: path="{{ zk_logDir }}" state=absent
      ignore_errors: True
      tags: uninstall,cluster-uninstall
    
    
    - name: "delete kafka_logdir directory"
      file: path="{{ kafka_logdir }}" state=absent
      ignore_errors: True
      tags: uninstall,cluster-uninstall
    
    
    - name: "delete redis_path_data directory"
      file: path="{{ redis_path_data }}" state=absent
      ignore_errors: True
      tags: uninstall,cluster-uninstall
    
    
    - name: "delete mysql_basedir directory"
      file: path="{{ mysql_basedir }}" state=absent
      ignore_errors: True
      tags: uninstall,cluster-uninstall
    
    - name: "delete mysql_datadir directory"
      file: path="{{ mysql_datadir }}" state=absent
      ignore_errors: True
      tags: uninstall,cluster-uninstall
    tasks/main.yml

         为了避免在执行安装服务的tasks时候,不执行卸载的task

        

       ansible-playbook  -i  hosts  --tags base  --skip-tags uninstall site.yml

       

     其他控制流

          ansible-playbook  -i  hosts  --tags  flink-master,flink-worker  --skip-tags uninstall  site.yml

          ansible-playbook  -i  hosts  --tags  elastic-uninstall  site.yml

         ansible-playbook -i hosts  --tags  cluster-uninstall  site.yml

     ansible修改主机名

             ansible-playbook 执行命令的时候会自动进行变量采集

             ansible执行命令的时候不会自动采集变量

           

  • 相关阅读:
    焦点事件中的Validating处理方法
    推荐一个快速反射调用的类
    VB.NET自我总结语法
    WinForm应用程序实现虚拟键盘
    将图片保存到XML文件的方法
    分享TextBoxLineEx控件
    自定义CancelEventArgs类,封装事件参数信息,实现e.Cancle=true取消机制。
    从sql server 中读取二进制图片
    Oracle数据库自我总结
    Android DroidDraw UI设计工具下载地址
  • 原文地址:https://www.cnblogs.com/yxh168/p/14871071.html
Copyright © 2020-2023  润新知