Error when using vars_files and vars_prompt in same playbook

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:

---

-
    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?

It looks like your vars_files aren't formatted as dicts. They should look
something like

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 ;-).

daniel_hozac is a machine!

Yep, this was the problem. I had an extraneous hyphen in both files.

Thanks for all the replies and help!

Andrew