I have a large role, which I will break down into separate roles eventually.

For the moment, I am trying to use tags to selectively run bits of it, 
tagged e.g. "server", "portal" etc.

The role is called from this playbook:

---

- hosts: localhost
  connection: local
  gather_facts: false

  pre_tasks:
     - include_vars: blah_envs/{{env}}.yaml
     - include_vars: blah_envs/common.yaml

  roles:
     - blah

The whole thing works fine if I just run that playbook, specifying a 
suitable value for "env".

However, if I also specify a tag on the command line e.g. "--tags server", 
Ansible gives me an error message:

   The task includes an option with an undefined variable

... and mentions a variable that is defined in one of the var files. It 
seems that those pre-tasks are not happening, a theory that is borne out by 
the fact that I usually see a status output listing the variables that have 
just been loaded, but I do not see that output when I specify a tag.

How can I get those variables to load and be available to the tagged tasks 
I am running?

If I put "tags: always" in the pre-tasks stanza, it appears to set the tag 
on the whole playbook, as everything runs, it doesn't just always load the 
vars.

Regards, K.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c369e1e6-7dce-4110-b580-55163a3d8a99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to