# Tags or Variables, not sure which way to go

**URL:** <https://forum.ansible.com/t/tags-or-variables-not-sure-which-way-to-go/33625>\
**Category:** Ansible Project\
**Created:** [August 16, 2020, 8:32pm UTC](https://forum.ansible.com/t/tags-or-variables-not-sure-which-way-to-go/33625 "2020-08-16T20:32:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcpetro](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jcpetro](https://forum.ansible.com/u/jcpetro)\
**Post date:** [August 16, 2020, 8:32pm UTC](https://forum.ansible.com/t/tags-or-variables-not-sure-which-way-to-go/33625/1 "2020-08-16T20:32:09Z")

</div>

So I am having an issue about not knowing what the best thing to do is. Here’s what I am trying to accomplish…

I have the following sanitized tasks:

- name: Set authorized key ( prod)

authorized\_key:  
user: ansible  
state: present  
key: “{{ lookup(‘file’, 'ssh public key file) }}”  
key\_options: ‘from=“Prod control node IP”’

- name: Set authorized key ( test)

authorized\_key:  
user: ansible  
state: present  
key: “{{ lookup(‘file’, 'ssh public key file) }}”  
key\_options: ‘from=“testlab control node IP”’

The key option specifies that only the ansible control node can use ssh keys to the ansible account.

So is there a way to say execute the prod task unless a “test” tag is passed? At the same time, I want to do the opposite with the test task, and say only execute if the “test” tag is passed. (I know how to do this second part),

My other option, would be to just set a variable, and I know I can do it that way, but wasn’t sure if I could do the same thing with a tag.

–John

---

<div class="post-metadata">

**Author:** ![acozine1](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@acozine1](https://forum.ansible.com/u/acozine1)\
**Post date:** [August 17, 2020, 5:17pm UTC](https://forum.ansible.com/t/tags-or-variables-not-sure-which-way-to-go/33625/2 "2020-08-17T17:17:57Z")

</div>

Hi John,

The opposite of “- -tags my\_tag” is “—skip-tags my\_tag” - see the updated documentation on tags at [https://docs.ansible.com/ansible/devel/user\_guide/playbooks\_tags.html](https://docs.ansible.com/ansible/devel/user_guide/playbooks_tags.html).

You would, of course, need to add tags to your task, block, or play before you could select or skip those tags at runtime.

Hope this helps,  
Alicia

---

<div class="post-metadata">

**Author:** ![jcpetro](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jcpetro](https://forum.ansible.com/u/jcpetro)\
**Post date:** [August 17, 2020, 5:46pm UTC](https://forum.ansible.com/t/tags-or-variables-not-sure-which-way-to-go/33625/3 "2020-08-17T17:46:03Z")

</div>

Thanks for the response. I did see that this morning, but hadn’t had a chance to test it out yet. I"ll give that option a shot and see if it’s better than the variable method I ended up writing.

–John
