The default ansible inventory format is only 'ini-like' so I wouldn't
expect tools for handling standard ini files (like the ini_file module) to
work well.
The examples you mention are good examples of where that falls apart.
Haven't ran the examples or dug in yet, but first thought is it looks like
this is implementing what inventory and the 'hosts:' keyword does.
I would try a more standard approach first, notes later...
As far as generating a inventory with ansible tasks... That smells like the
wrong approach to me.
inventory ini file looks a little odd to me. Having a group and a host with
the same name is confusing (data_storage)
Is 'data_storage_ver2' a valid resolveable hostname? if not, need to
provide a value for ansible_host
# main playbook
- include: library/add_NFS_domain.yml storage={{ item }}
with_inventory_hostnames: storage
(why is the yaml file in library/ ? library is usually for per playbook
ansible modules)
Where does ovirt_hosts come from?
try roughly:
# storage.ini (inventory)
data_storage storage_domain_name=name1 address1=12.12.12.12
path1=data_storage dc_name=DC1
data_storage_ver2 storage_domain_name=name2 address1=12.12.12.13
path1=data_storage2 dc_name=DC2
[storage]
data_storage
data_storage_ver2
# main playbook assuming ovirt_hosts and ovirt_auth is defined somewhere...
- name: ensure ovirt storage domains for each host
# apply to hosts in the 'storage' group
hosts: storage
- tasks:
- ovirt_hosts_facts:
pattern: "status=up and datacenter={{ dc_name }}"
auth: "{{ ovirt_auth }}"
- ovirt_storage_domains:
name: "{{ storage_domain_name }}"
host: "{{ ovirt_hosts[0].name }}"
data_center: "{{ dc_name }}"
auth: "{{ ovirt_auth }}"
nfs:
address: "{{ ip1 }}"
path: "{{ path1 }}"
On Sun, Aug 13, 2017 at 5:21 PM, chipcha <[email protected]> wrote:
> Hi all,
>
> Here are few examples of the differences between the two:
> 1. ini_file module - When adding a value with ini_file module the syntax
> must always be [key]=[value] even if there is no value:
> [webservers]
> foo=foo.example.com
> bar=None
>
> ansible docs - In the docs the ini file uses standalone names, so we can
> have a group with only hostnames, for example:
> [webservers]
> foo.example.com
> bar.example.com
>
> 2. ini_file module - It is not possible to declare host variables in a one
> liner:
> [atlanta]
> http_port=80
> maxRequestsPerChild=808
>
> ansible docs:
> [atlanta]
> host1 http_port=80 maxRequestsPerChild=808
>
> Also it seems that the ini_file module does not support reading from the
> ini file only insert or update.
>
> What do you recommend for the best approach? is there any other ansible
> module I can use to manipulate data in my INI file or should I use a
> different approach?
>
> Here is an example of my ini file:
> # INI file
> [data_storage]
> data_storage name=name1 address1=12.12.12.12 path1=data_storage dc_name=
> DC1
>
>
> [data_storage_ver2]
> data_storage_ver2 name=name2 address1=12.12.12.13 path1=data_storage2
> dc_name=DC2
>
>
> [storage:children]
> data_storage
> data_storage_ver2
>
>
> The playbook looks like this:
> # main playbook
> ....
> ....
> - include: library/add_NFS_domain.yml storage={{ item }}
> with_inventory_hostnames: storage
> ....
>
>
> # task file
> - ovirt_hosts_facts:
> pattern: "status=up and datacenter={{ hostvars[storage]['dc_name'] }}"
> auth: "{{ ovirt_auth }}"
>
>
> - ovirt_storage_domains:
> name: "{{ hostvars[storage]['name'] }}"
> host: "{{ ovirt_hosts[0].name }}"
> data_center: "{{ hostvars[storage]['dc_name'] }}"
> auth: "{{ ovirt_auth }}"
> nfs:
> address: "{{ hostvars[storage]['ip1'] }}"
> path: "{{ hostvars[storage]['path1'] }}"
>
>
>
> --
> 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/3e4a9e25-1853-4963-95e8-b65e1cc85b69%40googlegroups.
> com
> <https://groups.google.com/d/msgid/ansible-project/3e4a9e25-1853-4963-95e8-b65e1cc85b69%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAOJNLf_7O%2BRVr0JB694DN-2QqyRcZjDGnCfbEGN367ZBKp%2B5aw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.