项目架构
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时候,不执行卸载的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执行命令的时候不会自动采集变量