On 03. sep. 2016 19:27, Jon Langemak wrote:
I want to be able to run a task only when I pass a tag to the playbook.
 Namely, I want to have a tag that allows for decoming a user and one would
normally never run that as part of normal playbook run.

To my knowledge this is not possible to do with tags.
But you can do it with variables.


I found the conditional 'what: tags is defined' but it doesnt seem to work.
 My task looks like this...

- name: decom user
  shell:  echo test
  when: tag is defined

This will check if the variable tag is defined, since it's not it will skip the task.


  tags: decom

When I run it, I get this in the verbose output...


TASK [vyatta : decom user]
*****************************************************

skipping: [10.10.10.54] => {"changed": false, "skip_reason": "Conditional
check failed", "skipped": true}


I cant sort out why this is failing.  Im passing the tag as part of the
run...

ansible-playbook test.yml -t decom -v

Any ideas?  Thanks!

Instead of tags you can use variable.

  - name: decom user
    debug: msg="Yay I'm running"
    when: decom is defined

You can set the variable at run time like this

ansible-playbook test.yml -e "decom=true"

--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/eb037fa9-e74f-3498-c335-e8fbe2f54eff%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to