我想按照--tags中给出的标签顺序在ansible剧本中运行任务
我的剧本
--- - hosts: all remote_user: root vars: file_path: '{{filename}}' tasks: - name: Delete user user: name: "{{username}}" state: absent remove: yes tags: - delete_user - name: Create user user: name: "{{username}}" shell: /bin/bash groups: "{{groupname}}" password: "{{ password |password_hash('sha512') }}" tags: - create_user - name: Add ssh key authorized_key: user: "{{username}}" key: "{{lookup('file', 'file_path')}}" exclusive: yes tags: - add_ssh_key
运行Ansible
ansible-playbook createuser.yml --extra-vars "username=hello password=helloworld groupname=something filename=/path/to/filename" --tags=create_user,add_ssh_key,delete_user
预期产量
TASK: [Create user] *********************************************************** changed: [ip address] TASK: [Add ssh key] *********************************************************** changed: [ip address] TASK: [Delete user] *********************************************************** ok: [ip address]
输出来
TASK: [Delete user] *********************************************************** ok: [ip address] TASK: [Create user] *********************************************************** changed: [ip address] TASK: [Add ssh key] *********************************************************** changed: [ip address]
给定标签的顺序
create_user,add_ssh_key,delete_user
但是按顺序执行
delete_user,create_user,add_ssh_key,