Variables from executable inventory not working in playbook

All,
On the latest devel, I am using an executable inventory that returns this:

% ./hosts testhost
{
   "webtype" : "webapp"
}

But when I run a playbook that includes a file with a task that
includes $webtype like this, it doesn't seem to get replaced by the
string "webapp";

- name: copy ssl.conf
  action: copy src=$conf/web/templates/$stack/ssl.conf.$webtype
dest=/foo/ssl.conf owner=root group=root mode=0644

The error I see is this:

fatal: [testhost] => file or module does not exist:
/ansible/conf/web/files/prod/httpd.conf.$webtype

Note that it did replace $conf and $stack appropriately, but $conf is
set from a vars_files file, and $stack is set from a "vars:" entry
directly in the playbook. I know this is supposed to work, right?
Does anyone have suggestions for troubleshooting?

thanks!
matt

Wrong return structure. Correct is:

{

whatever: “…”

ansible_facts: {
webtype: “webapp”
}

}

Thanks Michael, I thought for sure that would fix it, but I'm still
seeing the same error. ansible_ssh_port is definitely working, so i
know this is getting parsed. Here is exact json returned now for one
of my systems seeing that error:

{
   "ansible_ssh_port" : 222,
   "ansible_facts" : {
      "apacheconf" : "/etc/httpd",
      "webtype" : "webapp"
   }
}

thanks,
matt

Did you call the module before you referenced the fact?

Are you using the devel branch?

Did you call the module before you referenced the fact?

These variables aren't coming from a module, they're coming from an
executable inventory. I was following the instructions at
http://ansible.github.com/api.html#external-inventory, which is why I
hadn't known about the ansible_facts key (I also noticed that you need
to call the inventory with a "--list" argument instead of no argument
as documented to return the inventory itself). From that
documentation, I'm assuming I can set a bunch of variables for use
within the playbook by calling my inventory script with the host as an
argument.

Are you using the devel branch?

Yup, I am using the latest devel.

thanks,
matt

Yeah, those work differently.

The --list thing is a regression that should be fixed.

Hi Matt,

This has been that way since I started using ansible and before any
inventory rewrite... So the best option is to edit the docs, since
anyone who's using ansible will be using --list and --host.

Greetings,

Jeroen

Sorry, I reread the doc and see those are only available to templates,
not to playbooks. Bummer. I'll need to write a module to provide the
facts to the playbooks. Modules are executed only on the remote host
though, not on the ansible master? I have a bunch of variables that
the master knows about in my environment that I'd like to be able to
use in playbooks.

@Jeroen, saw your update just now: adding --host doesn't seem to help,
I suspect because I'm trying to use variables in playbooks that are
only available to templates...

matt

It works for me. Complete example at https://gist.github.com/2662146

Jeroen

Thank you Jeroen! I will report back when I figure out what my problem is.

matt

Thank you Jeroen! I will report back when I figure out what my problem is.

Figured it out. When using the executable inventory you DO need to
pass the --host argument to your inventory script, but you should NOT
return ansible_facts, just return a flat list of variables as the docs
describe. http://ansible.github.com/api.html#script-conventions could
be fixed by replacing "When the external node script is called with no
arguments" with "When the external node script is called with the
argument '--list'", and replacing "When called with a single argument,
the name of a host from above" with "When called with arguments
'--host <hostname>'".

matt

Agreed

-- Michael

Sorry, I reread the doc and see those are only available to templates,
not to playbooks

I wrote the docs, I believe you misread, but show me.

at http://ansible.github.com/api.html#script-conventions it says "When
called with a single argument, the name of a host from above, the
script must return either an empty JSON hash/dictionary, or a list of
key/value variables to make available to templates". So, you're
correct it doesn't actually say _only_ available to templates. I just
read it that way when I was having so much trouble getting the
variables to work in playbooks.

I've submitted a pull request for the changes that were discussed in
this thread...

https://github.com/ansible/ansible.github.com/pull/107

matt