Sorry that --list-tags was meant to be just "--tags" ansible-playbook foo.yml --tags NotATagNameJustShowMeTheTags
On Wed, Apr 16, 2014 at 10:19 PM, Michael DeHaan <[email protected]>wrote: > So yeah. > > There's been interest in adding such before, my requirement is usually > that it uses the Playbook API to do these things. > > Some things are going to require a minor bit of refactoring to make some > of that later. > > I generally want to avoid special code specific to /usr/bin/ansible > commands that are not contained in playbook API code. > > I'd generally think needing the stats class would be "not it". > > Workaround for now has been to just specify an invalid tag and it will > list available tags, so that is pretty close, but it happens > as a result of a "live" run, so I understand that's not quite what you > want. > > Example: > > ansible-playbook foo.yml --list-tags NotATagNameJustShowMeTheTags > > > > On Wed, Apr 16, 2014 at 3:38 AM, Michael Nelson <[email protected]>wrote: > >> On Fri, Mar 7, 2014 at 4:52 PM, Michael Nelson <[email protected]> >> wrote: >> > >> > >> > On Friday, 7 March 2014 16:31:45 UTC+1, Michael Nelson wrote: >> >> >> >> Hi! >> >> >> >> Just a heads-up that I'm thinking of adding a --list-tags option to >> >> ansible-playbook. Let me know if there's a reason why that wouldn't be >> a >> >> good idea, or it's not needed etc. >> >> >> >> My use-case is that I'd like to know in advance whether a tag is >> included >> >> in the playbook, rather than running the playbook and erroring. I can >> >> currently work around this by parsing the error output of >> `ansible-playbook >> >> --tags random-hash myplaybook`, but I'd like a nicer way :) >> > >> > >> > Actually, I've just taken a look at the code and seen that, given that >> I'm >> > already using python helpers for the ansible support, I could just use >> > ansible.playbook.Play().compare_tags() directly. So no change needed :) >> > >> >> Just getting back to this - it seems quite complicated to get the tags >> for a playbook... here's the helper function that I have: >> >> {{{ >> def get_tags_for_playbook(playbook_path): >> """Return all tags within a playbook.""" >> # utils imported first to avoid circular import failure. >> import ansible.utils >> import ansible.callbacks >> import ansible.playbook >> stats = ansible.callbacks.AggregateStats() >> callbacks = ansible.callbacks.PlaybookRunnerCallbacks(stats) >> runner_callbacks = >> ansible.callbacks.PlaybookRunnerCallbacks(stats) >> playbook = ansible.playbook.PlayBook(playbook=playbook_path, >> >> callbacks=callbacks, >> >> runner_callbacks=runner_callbacks, >> stats=stats) >> myplay = ansible.playbook.Play(playbook, ds=playbook.playbook[0], >> >> basedir=os.path.dirname(playbook_path)) >> >> _, playbook_tags = myplay.compare_tags([]) >> playbook_tags.remove('all') >> return playbook_tags >> }}} >> >> Perhaps it is worth a feature request - let me know if this should be >> easier or if I've missed something above? >> >> Thanks. >> -Michael >> >> -- >> 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/CABgyWipybYRJGkwt4MgXgOZcWNEE4bYOiZZeuac8PeTCApebzw%40mail.gmail.com >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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/CA%2BnsWgz3cWrnp3D2yc0b9miFAc0nb%3DO_G6OoRFy9gvJbKAWp0g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
