I want to update INI configuration files.
Today, I store my informations in a var file (in group_vars) this way :
# Identity configuration information
identity_servers_conf:
DEFAULT:
admin_token: "{{identity_admin_token}}"
verbose: True
database:
connection: "mysql://{{ identity_db_user }:{{ identity_db_password }}@{{ db_lb_name }}/{{ identity_db }}"
token:
provider: keystone.token.providers.uuid.Provider
driver: keystone.token.persistence.backends.sql.Token
In my Ansible task, I use these informations this way:
- name: configuration / modify keystone.conf ini file DEFAULT section
ini_file:
section: DEFAULT
dest: /etc/keystone/keystone.conf
option: "{{item.key}}"
value: "{{item.value}}"
with_dict: identity_servers_conf['DEFAULT']
And I duplicate this task for every sections.
Is there a way to iterate through my dict file with each "section" parameters, i.e DEFAULT, database, token.
In fact, I try to find a way to do a with_dict nested in a with_items loop.
hello,
I find very interesting this way of organizing variables for .ini files.
I wanted to use it myself, so I worked on a plugin that allows to generate all the keys of an .ini file in one pass with the inifile module.
It works fine and I use to manage my OpenStack configuration files.
I am not a specialist in development, but I think this plugin can be useful for everyone, so if someone wants to take over to maintain and integrate it into ansible, he is welcome.
The plugin transforms the hierarchy data in a list (section, key, value) for use directly with the inifile module with_inidata as below:
vars file :
`
…
glanceapi_conf:
DEFAULT:
verbose: “{{ image_log_verbose }}”
rabbit_host: “{{ amqp_host }}”
rabbit_port: “{{ amqp_port }}”
rabbit_userid: “{{ amqp_userid }}”
rabbit_password: “{{ amqp_password }}”
rabbit_ha_queues: “{{ amqp_ha_queues }}”
database:
connection: “mysql://{{ image_db_user }}:{{ image_db_password }}@{{ db_host }}/{{ image_db }}”
keystone_authtoken:
auth_uri: “http://{{ identity_admin_host }}:{{ identity_api_port }}/v2.0”
identity_uri: “http://{{ identity_admin_host }}:{{ identity_admin_port }}”
admin_tenant_name: “{{ image_ks_tenant }}”
admin_user: “{{ image_ks_user }}”
admin_password: “{{ image_ks_password }}”
paste_deploy:
flavor: keystone
glance_store:
default_store: file
filesystem_store_datadir: /var/lib/glance/images/
…
`
plugin code :
`
I would be tempted to keep it as a dictionary, but just to render the INI file using the template module.
That way additional lookup plugins can be avoided.
Hello and thank you for your quick response.
In my opinion, to use a template, you must retrieve or generate it and keep it alive (track changes).
You must also manage the template and variable files.
With this solution, we only manage the specific keys in a single variables file.
This is very visual and updating it can be done very easily.
Best Regards