ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
93 stars 19 forks source link

Wildcarding/Regex Matching for Section in ini_files Module #100

Open wizlon72 opened 6 years ago

wizlon72 commented 6 years ago

Proposal: Wildcarding/Regex Matching for Section in ini_files Module

Author: Wilson Weber<@wizlon72>

Date: 2018/03/08

Motivation

ini_files is extremely useful for modifying a single stanza in an INI file. If multiple stanzas need modification it can become inefficient to list each stanza individually. The replace module isn't a perfect fit as in some cases the stanza may have/not have the existing attribute already - so it isn't a consistent find/replace behavior.

Problems

What problems exist that this proposal will solve? Enumerating each stanza individually can lead to unnecessarily lengthy playbooks, or in some case you may not know every stanza and wish to match on part of the stanza.

Solution proposal

Allowing section to take a regex instead of an explicit string would allow for broader matching.

One problem this would potentially cause would be that currently if the stanza is not found it creates the stanza, if entering a regex in section you would need to disable this functionality.

Seems the best way to do this would be to add an additional attribute labeled 'section-regex' and when enabled the section mapping happens based on the regex and disables the new stanza creation statement.

Testing (optional)

Validate that the regex will match multiple times within a single file. Validate that if the regex does not match within a file no new stanza is created.

Documentation (optional)

Anything else?