After upgrading from 1.1 to 1.2, the user module no longer picks up variables defined in vars_file if relative path is used

I upgrade ansible from 1.1 to 1.2 a few days ago (by git clone and then make deb) on my notebook running Ubuntu 11.04 64 bit.

I soon noticed that my existing playbook for adding users no longer sets a user’s password correctly. To test, I took the ansible-examples/language_features/user_commands.yml at master · ansible/ansible-examples · GitHub and simplified it into the attached two versions:

  1. user_vars_files_cli.yml
  2. user_vars_files_explicit.yml
    together with an external user_passwords.yml residing in a subdirectory vars.

The two files are residing in /home/zperry/Desktop
The user_passwords.yml resides in /home/zperry/Desktop/vars

I ran 1. above like so:
$ ansible-playbook user_vars_files_cli.yml --extra-vars “hosts=nb1 user=root vars_files=vars/user_passwords.yml” -v

On the target system (nb1, a netbook running SL 6.3), the /etc/shadow has a {{tset_password}} in it literally ;-(

I ran 2 above like so:
$ ansible-playbook user_vars_files_explicit.yml --extra-vars “hosts=nb1 user=root” -v

This one works OOTB as anticipated. But I don’t like it since it has a hard-coded path for the external vars_files

My questions:

  1. Has the relative path handling changed since 1.2?
  2. How can I get the more flexible (and thus IMHO more desirable) 1. to work with relative path as I have been doing?
    Thanks for any hints.

– Zack

(attachments)

user_vars_files_cli.yml (412 Bytes)
user_passwords.yml (119 Bytes)
user_vars_files_explicit.yml (384 Bytes)

Can you please send YAML you are asking to the list inline rather than as attachments, or use gist to show structure?

This requires us downloading your files and putting them in the right place, and I’m rather tired to do homework :slight_smile:

Thanks for understanding!

–Michael

Also please be sure to illustrate your problem in your uploaded files by putting in some comments, highlighting what variables work and don’t, and so on.

Thanks Michael. See below:

(A) user_vars_files_cli.yml

Ah, vars_files is being passed in as a list! Got it, thanks…

Yeah, I didn’t really expect that to be ever done per se, and the code isn’t really going to make list variables expand like magic if they start as strings now, that’s true and was a consequence of trying to get variables back under control (which we did!)

You can definitely do:

vars_files:

  • “{{ some_variable_file_path }}”

Note, I’m favoring the new variable syntax available in 1.2, it’s simpler because it is the same as in templates, and you don’t have to remember any weird rules for deferenceing arrays or hashes or strings with dots in them. Note that if you start a line with “{{” you must quote the line, because YAML likes it that way.

I should also point out one thing new in 1.2 is --extra-vars can be passed in as quoted JSON if you really want to. Not sure if that helps but can be a great way to define structured data.

Hi Michael,

Ah, vars_files is being passed in as a list! Got it, thanks…

Yup! I have been doing so since ansible 0.4 all the way to 1.1. So, when in 1.2 such usage failed me, I was a bit deflated :wink:

Yeah, I didn’t really expect that to be ever done per se, and the code isn’t really going to make list variables expand like magic if they start as strings now, that’s true and was a consequence of trying to get variables back under control (which we did)

I RTFMed after dinner and found this role. It somewhat helps. But it’s also quite strict. For example, per http://www.ansibleworks.com/docs/playbooks.html#roles,
I mkdir roles/common/vars
but then ansible-playbook user_vars_files_roles.yml --extra-vars “hosts=nb1 user=root vars_files=user_passwords.yml” --list-hosts refused to run until I also created

  • roles/common/files/main
  • roles/common/tasks/main
  • roles/common/handlers/main
  • roles/common/library

8-( A lot of extra stuff that I don’t need for now. But at least it works with a mv roles/common/vars/user_passwords.yml roles/common/vars/main.yml
as instructed by http://www.ansibleworks.com/docs/playbooks.html#roles

The following simply test playbook works: