Hi Michael, Thank you for your feedback.
On 10-09-14 15:26, Michael DeHaan wrote:
Yes, where you are defining "test" some of the items in that list are hash tables that don't have a value for "base", which is why you are getting that error.
Clearly I need to read more about lists, hashes and dicts. Not being a developer, please stand by while I try to wrap my head around them :)
Easiest would be to set it to empty string when it does not apply.
I couldn't figure that out but in the docs I found 'Nested Loops' that seemed promising. For the archives, here's how I got it working:
------ # file: roles/common/tasks/main.yml - name: dirs | Include vars include_vars: main.yml - name: dirs | Create some directories file: dest: "{{ item.0.base }}{{ item.0.usr }}/{{ item.1 }}" mode: 0750 state: directory with_nested: - users - dirs --- # file: roles/common/vars/main.yml users: - usr: patrick base: /home/ - usr: root base: / dirs: - test1 - test2
However, it's a little weird that it says "str object", which seems to imply you have, probably in that "dirs" variable file, refined the variable "test" to a list of strings, as opposed to a list of hash elements.
FWIW it's Ansible 1.7.1 on Fedora 20 x86_64. If weird means bug, please let me know if you'd like me to file a ticket on github.
Thanks, Patrick
On Tue, Sep 9, 2014 at 7:12 PM, Patrick Ansible-ML <ansi...@puzzled.xs4all.nl <mailto:ansi...@puzzled.xs4all.nl>> wrote: Hi all, New to the list. Been playing with Ansible for a few hours and I could use a hand in getting a task going. I've not figured out any of the YAML magic so please excuse the undoubtedly spectacular errors :) Goal: create a task that installs a couple of directories in /home/patrick and /root. --- # file: roles/common/tasks/main.yml - name: dirs | Include vars include_vars: main.yml - name: dirs | Create some directories file: dest: "{{ item.base }}/{{ item.usr }}/{{ item.dirs }}" mode: 0750 owner: "{{ item.usr }}" group: "{{ item.usr }}" state: directory with_items: test --- # file: roles/common/vars/main.yml test: - usr: patrick base: /home - usr: root base: / - dirs: test1 - dirs: test2 When I run this with: $ ansible-playbook -v -i stage site.yml I get: TASK: [common | dirs | Create some directories] ******************************__* fatal: [test.local] => One or more undefined variables: 'str object' has no attribute 'base' I'm guessing that the issue is in vars/main.yml file but lots of Googling and staring at Github/Galaxy examples did not reveal a solution. Can anyone please enlighten me a bit? Thanks, Patrick
-- 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/5410724D.70401%40puzzled.xs4all.nl. For more options, visit https://groups.google.com/d/optout.