Load only certain tags from role from Ansible play - Stack Overflow

Let's say that I have a role# foo.yml---- name: A tasktags: tag_Adebug:msg: "A task"-

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 badges
Add a comment  | 

1 Answer 1

Reset to default 3

Q: "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

  1. The environment variable. ANSIBLE_RUN_TAGS=tag_B

  2. The configuration section [tags] run=tag_B

  3. 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

相关推荐

  • Load only certain tags from role from Ansible play - Stack Overflow

    Let's say that I have a role# foo.yml---- name: A tasktags: tag_Adebug:msg: "A task"-

    2天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信