How best to express desired merged or replaced state for module that accepts a list of items

I’m working on the pfsensible.core.pfsense_dns_resolver module and am looking for suggestions on how to express something. It accepts two lists of items: domainoverrides and hosts. Currently it will replace all of each with the items passed to the module. Users would like to be able have the call simply add/modify the items in the list but keep any existing items. I’d like suggestions on how to express this in the module.

I think I’d like to avoid using the state option, but could explore it if it is the recommended way to do it.

Thanks!

The aws modules do this with purge_ options, for example amazon.aws.ec2_group has purge_tags which defaults to True, so tags are replaced by default, but only if the tags parameter is provided.

That seems reasonable to me. Thanks.

Another example is:

https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html

and option called exclusive. It tells the module to remove anything that is not specified in a list. In your case you would have multiple options like domainoverrides_exclusive and hosts_exclusive, both boolean values. I think exclusive as a word better describes the intent than purge. It’s more declarative.

1 Like