Let's say that I have a role
# foo.yml
---
- name: A task
tags: tag_A
debug:
msg: "A task"
- name: B task
tags: tag_B
debug:
msg: "B task"
Now I want to create a playbook that will call the role foo
, but only run the tag tag_B
. I know that I can pass the --tags
flag to the ansible-playbook
command, but I want to do this every time and I don't want users to have to know to provide that flag? How do I call that role and only get the B_task
task? I've tried
roles:
- { role: 'foo', tags: 'tag_B' }
and
tasks:
- include_role: foo
tags: tag_B
But these just APPLY the tag to all of the tasks, it doesn't filter the tasks. I don't want to run all of the them, just the one.
Let's say that I have a role
# foo.yml
---
- name: A task
tags: tag_A
debug:
msg: "A task"
- name: B task
tags: tag_B
debug:
msg: "B task"
Now I want to create a playbook that will call the role foo
, but only run the tag tag_B
. I know that I can pass the --tags
flag to the ansible-playbook
command, but I want to do this every time and I don't want users to have to know to provide that flag? How do I call that role and only get the B_task
task? I've tried
roles:
- { role: 'foo', tags: 'tag_B' }
and
tasks:
- include_role: foo
tags: tag_B
But these just APPLY the tag to all of the tasks, it doesn't filter the tasks. I don't want to run all of the them, just the one.
Share Improve this question asked Mar 10 at 18:56 FuriousGeeFuriousGee 4,7095 gold badges36 silver badges55 bronze badges1 Answer
Reset to default 3Q: "Create a playbook that will call the role foo, but only run the tag tag_B."
A: It is not posible to declare TAGS_RUN and TAGS_SKIP inside a playbook. There are three options only that must be declared before a play starts
The environment variable.
ANSIBLE_RUN_TAGS=tag_B
The configuration section [tags]
run=tag_B
The option --tags
ansible-playbook --tags tag_B pb.yml
In addition to this you can use Ansible Runner and put the tags into the file env/cmdline.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744828913a4595965.html
评论列表(0条)