Re: [ansible-project] Error when using vars_files and vars_prompt in same playbook

577 views
Skip to first unread message

Michael DeHaan

unread,
Jan 31, 2013, 2:22:45 PM1/31/13
to ansible...@googlegroups.com
On Thu, Jan 31, 2013 at 2:19 PM, Andrew Berman <atbe...@gmail.com> wrote:
> Hello,
>
> I'm new to Ansible and I'm not sure if this is a bug or if I'm doing
> something wrong. I currently have a playbook which has vars_prompt and
> vars_files in it and no matter what I do, I get a Python error. Here is
> the playbook:

Ok, this is the classic computer error of an error being raised while
it is trying to tell you what the actual error really was.

It looks like you want to do

- name:

as opposed to

- (newline)
name:

at least at first glance.

We should definitely intercept the error condition such that we don't
give you a traceback in that case, so that itself is a bug. Can you
file one and make sure the playbook you used to reproduce it is in the
ticket?

Otherwise, fixing the format error should make the error (and the
traceback) disappear. Using vars_files/vars_prompt together is
definitely legal.

Hope that helps!

--Michael

>
> ---
>
> -
> hosts: $hosts
>
> user: root
>
> vars_prompt:
> -
> name: pg_port
> prompt: "What port should Postgres run on?"
> private: no
> default: 5432
>
> vars_files:
> - vars/postgres.yml
> - vars/global_vars.yml
>
> It works only when I comment out the entire vars_files block. Here is the
> Python error:
>
> Traceback (most recent call last):
> File "/usr/bin/ansible-playbook", line 177, in <module>
> sys.exit(main(sys.argv[1:]))
> File "/usr/bin/ansible-playbook", line 148, in main
> pb.run()
> File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line
> 192, in run
> play = Play(self, play_ds, play_basedir)
> File "/usr/lib/python2.6/site-packages/ansible/playbook/play.py", line 83,
> in __init__
> self._update_vars_files_for_host(None)
> File "/usr/lib/python2.6/site-packages/ansible/playbook/play.py", line
> 300, in _update_vars_files_for_host
> raise errors.AnsibleError("%s must be stored as dictonary/hash: %s" %
> filename4)
> TypeError: not enough arguments for format string
>
> Can anyone help me?
>
> Thanks,
>
> Andrew
>
> --
> 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-proje...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Daniel Hokka Zakrisson

unread,
Jan 31, 2013, 2:27:37 PM1/31/13
to ansible...@googlegroups.com
Andrew Berman wrote:
> Hello,
>
> I'm new to Ansible and I'm not sure if this is a bug or if I'm doing
> something wrong. I currently have a playbook which has vars_prompt and
> vars_files in it and no matter what I do, I get a Python error. Here is
> the playbook:
>
It looks like your vars_files aren't formatted as dicts. They should look
something like

---
var_a: value
var_b: valuedos

Daniel

elektrokokke

unread,
Jan 31, 2013, 2:44:23 PM1/31/13
to ansible...@googlegroups.com, dan...@hozac.com
And if you update from Git, you'll even see which one of your var_files is invalid, because a friendly person named dhozac has fixed the format string error a few minutes ago ;-).

Michael DeHaan

unread,
Jan 31, 2013, 2:56:28 PM1/31/13
to ansible...@googlegroups.com, dan...@hozac.com
daniel_hozac is a machine!

Andrew Berman

unread,
Jan 31, 2013, 3:03:42 PM1/31/13
to ansible...@googlegroups.com, dan...@hozac.com
Yep, this was the problem. I had an extraneous hyphen in both files.  

Thanks for all the replies and help!

Andrew
Reply all
Reply to author
Forward
0 new messages