Thanks for replying.

At the moment no, there aren't any csv files anywhere. Just trying out 
different approaches to config management using ansible. I'm comfortable 
with group_vars, it's the repetition in defining them that grates.

If you have a spare few minutes, take a look at Neil Watson's blog, 
specifically this post 
<http://evolvethinking.com/blog/2014/02/26/my-evolution-of-cfengine-policy/> 
explaining 
the evolution of his Cfengine policies. I've used this approach at a 
previous shop that had CFengine deployed and it worked well.
It makes viewing and managing configuration much easier, the idea of 
data-driven policies appeals.It also simplifies operations view of managing 
the infrastructure, one line specifies multiple configuration parameters 
for an object.

So...not what I wanted to hear but, not the end of the world either.

Just noticed I hadn't set the delimiter parameter, however still get the "
...unable to convert to bool" message.

Asil




On Monday, October 3, 2016 at 3:05:17 PM UTC+1, J Hawkesworth wrote:
>
> Presumably you've got csv files coming from somewhere else that you want 
> to use to drive things?
>
> If not, I'd suggest to you see if you can use group_vars 
> http://docs.ansible.com/ansible/intro_inventory.html#group-variables to 
> set variables for specific groups.  Bear in mind you can have multiple 
> groups and you can have groups which are specific to just one inventory 
> file or are shared, so they can be pretty flexible.
>
> I think using group_vars would 'go with the grain' better than using the 
> lookups, and give you more readable playbooks.
>
> Probably not what you wanted to hear, but hope it helps,
>
> Jon
>
>
> On Monday, October 3, 2016 at 10:18:15 AM UTC+1, Asil Carlin wrote:
>>
>> Hi,
>>
>> I'm trying to use csvfile lookups to populate values in the groups 
>> module, but not having much luck. My csvfile:
>>
>> # groups.csv
>> # name, gid [optional - leave blank], state [present|absent], system 
>> [yes|no]
>>  accounts,502,present,no
>> engineering,504,present,no
>>
>> The playbook:
>>
>> ---
>>
>> - hosts: localhost
>>   become: True
>>   become_user: root
>>
>>   tasks:
>>
>>   - name: get groups
>>     command: /usr/bin/awk -F',' '!/^#/ && !/^$/ { print $1 }' groups.csv
>>     register: groups_out
>>
>>   - name: Process groups
>>     group: >
>>       name="{{ lookup('csvfile', 'item file=groups.csv col=0') }}"
>>       gid="{{ lookup('csvfile', 'item file=groups.csv col=1') }}"
>>       state="{{ lookup('csvfile', 'item file=groups.csv col=2') }}"
>>       system="{{ lookup('csvfile', 'item file=groups.csv col=3') }}"
>>     # with_lines: "/usr/bin/awk -F',' '!/^#/ && !/^$/ { print $1 }' 
>> groups.csv"
>>     # with_items: "{{ groups_out.stdout_lines }}"
>>     with_lines: "{{ groups_out.stdout_lines }}"
>>
>>  Using with_lines and groups_out.stdout_lines gives me:
>>
>> TASK [Process groups] 
>> **********************************************************
>> /bin/sh: accounts: command not found
>> fatal: [localhost]: FAILED! => {"failed": true, "msg": 
>> "lookup_plugin.lines(accounts) 
>> returned 127"}
>>
>> Using with_items or with_lines and the awk command directly gives me:
>>
>> TASK [Process groups] 
>> **********************************************************
>> failed: [localhost] (item=accounts) => {"failed": true, "item": 
>> "accounts", "msg": "argument system is of type <type 'list'> and we were 
>> unable to convert to bool"}
>> failed: [localhost] (item=engineering) => {"failed": true, "item": 
>> "engineering", "msg": "argument system is of type <type 'list'> and we 
>> were unable to convert to bool"}
>>
>> Removing the loop and just specifying a key, in the following output 
>> "accounts" was used:
>>
>> TASK [Process groups] 
>> **********************************************************
>> fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": 
>> "argument 
>> system is of type <type 'list'> and we were unable to convert to bool"}
>>
>> Ultimately I'd like to use csv files to define config although I'm not 
>> sure i'm going about this the right way.
>>
>> Asil
>>
>>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/673b041c-e3d9-49db-9131-e0af04a4b914%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to