Issue understanding variables and with_items

36 views
Skip to first unread message

Gabriel Forster

unread,
Apr 4, 2017, 1:11:52 PM4/4/17
to Ansible Project
I think my issue is that I'm trying to get with_items to do too much. But when I use user.uniq instead of with_items, I'm getting a similar error. I'm really not understanding what approach to take. Thanks,

Here is the task:

 - name: Create New Version Directories in User's Home Dir
   file: path={{ home_path }}/home/{{ item.uniq }}/validator/{{ item }} mode=0755 owner={{ item.uniq }} group={{ group_devel }} state=directory
   with_items:
     - "{{ user }}"
     - "{{ validator_ver }}"
     - "{{ validator_ver }}/log"
     - "{{ validator_ver }}/config"



Here is the relevant var from the var/main.yml


user:
   
- { name: "HeyYou", uniq: "myself", validator_port: "1078" }


Here is the error:


TASK
[netiq-validator : Create New Version Directories in User's Home Dir] *****
--- before
+++ after
@@ -1,4 +1,4 @@
 {
     "path": "/home/myself/validator/{u'
validator_port': u'1078', u'uniq': u'myself', u'name': u'HeyYou'}",
-    "state": "absent"
+    "state": "directory"
 }
changed: [p-idm-bot1] => (item={u'
validator_port': u'1078', u'uniq': u'myself', u'name': u'HeyYou'})
fatal: [p-idm-bot1]: FAILED! => {"failed": true, "msg": "the field '
args' has an invalid value, which appears to include a variable that is undefined. The error was: 'float object' has no attribute 'uniq'\n\nThe error appears to have been in 'ansible/roles/netiq-validator/tasks/main.yml': line 17, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create New Version Directories in User's Home Dir\n  ^ here\n"}


Kai Stian Olstad

unread,
Apr 5, 2017, 6:38:50 AM4/5/17
to ansible...@googlegroups.com
On 04.04.2017 19:11, Gabriel Forster wrote:
> I think my issue is that I'm trying to get with_items to do too much.
> But
> when I use user.uniq instead of with_items, I'm getting a similar
> error.
> I'm really not understanding what approach to take. Thanks,
>
> Here is the task:
>
> - name: Create New Version Directories in User's Home Dir
> file: path={{ home_path }}/home/{{ item.uniq }}/validator/{{ item }}
> mode=0755 owner={{ item.uniq }} group={{ group_devel }} state=directory
> with_items:
> - "{{ user }}"
> - "{{ validator_ver }}"
> - "{{ validator_ver }}/log"
> - "{{ validator_ver }}/config"

I'm not sure I understand what you are trying to do, since the
with_items list is a mix of different data.

with_items will in you code run the module file 4 times.
1. First time with item = "{{ user }}"
2. Second time with item = "{{ validator_ver }}"
3. Third time with item = "{{ validator_ver }}/log"
4. Last time with item = "{{ validator_ver }}/config"

item.uniq will only be avaiable on the first run since that is the only
one that contains the key.

So for owner you are probably looking for "{{ user.uniq }}" and remove
the - "{{ user }}" form the list.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages