1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

lxd_container: do not ignore volatile configs by option (#3331) (#3411)

* do not ignore volatile - fix #2466

* remove unnecessary checks

* fix ansible-tests sanity

* fix access to the option: ignore_volatile_options

* add fragment

* fix quotation marks error

* fix review findings

* fix sanity error

* fix description - in yaml examples use true not True
comment out the deprecate message

* remove "default=True" at ignore_volatile_options
fix spelling

* fix sanity error that ignore_volatile_options have no default value

* undo changes. add defaut value and remove keyword at dict.get()

* fix sanity error

* small spelling fixes

* change text for fragment

* Fix description sentence.

Co-authored-by: Frank Dornheim <“dornheim@posteo.de@users.noreply.github.com”>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 8e7d49c1c6)

Co-authored-by: Frank Dornheim <524257+conloos@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-09-20 21:40:55 +02:00 committed by GitHub
parent b495035923
commit cfc28a3f6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 9 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "lxd_container - add ``ignore_volatile_options`` option which allows to disable the behavior that the module ignores options starting with ``volatile.`` (https://github.com/ansible-collections/community.general/pull/3331)."

View file

@ -31,16 +31,24 @@ options:
description: description:
- 'The config for the container (e.g. {"limits.cpu": "2"}). - 'The config for the container (e.g. {"limits.cpu": "2"}).
See U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1)' See U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1)'
- If the container already exists and its "config" value in metadata - If the container already exists and its "config" values in metadata
obtained from obtained from GET /1.0/containers/<name>
GET /1.0/containers/<name>
U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10containersname) U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10containersname)
are different, they this module tries to apply the configurations. are different, this module tries to apply the configurations.
- The key starts with 'volatile.' are ignored for this comparison. - The keys starting with C(volatile.) are ignored for this comparison when I(ignore_volatile_options=true).
- Not all config values are supported to apply the existing container.
Maybe you need to delete and recreate a container.
type: dict type: dict
required: false required: false
ignore_volatile_options:
description:
- If set to C(true), options starting with C(volatile.) are ignored. As a result,
they are reapplied for each execution.
- This default behavior can be changed by setting this option to C(false).
- The default value C(true) will be deprecated in community.general 4.0.0,
and will change to C(false) in community.general 5.0.0.
type: bool
default: true
required: false
version_added: 3.7.0
profiles: profiles:
description: description:
- Profile to be used by the container - Profile to be used by the container
@ -176,6 +184,7 @@ EXAMPLES = '''
- name: Create a started container - name: Create a started container
community.general.lxd_container: community.general.lxd_container:
name: mycontainer name: mycontainer
ignore_volatile_options: true
state: started state: started
source: source:
type: image type: image
@ -209,6 +218,7 @@ EXAMPLES = '''
- name: Create a started container - name: Create a started container
community.general.lxd_container: community.general.lxd_container:
name: mycontainer name: mycontainer
ignore_volatile_options: true
state: started state: started
source: source:
type: image type: image
@ -279,6 +289,7 @@ EXAMPLES = '''
- name: Create LXD container - name: Create LXD container
community.general.lxd_container: community.general.lxd_container:
name: new-container-1 name: new-container-1
ignore_volatile_options: true
state: started state: started
source: source:
type: image type: image
@ -289,6 +300,7 @@ EXAMPLES = '''
- name: Create container on another node - name: Create container on another node
community.general.lxd_container: community.general.lxd_container:
name: new-container-2 name: new-container-2
ignore_volatile_options: true
state: started state: started
source: source:
type: image type: image
@ -557,7 +569,7 @@ class LXDContainerManagement(object):
def _needs_to_change_container_config(self, key): def _needs_to_change_container_config(self, key):
if key not in self.config: if key not in self.config:
return False return False
if key == 'config': if key == 'config' and self.ignore_volatile_options: # the old behavior is to ignore configurations by keyword "volatile"
old_configs = dict((k, v) for k, v in self.old_container_json['metadata'][key].items() if not k.startswith('volatile.')) old_configs = dict((k, v) for k, v in self.old_container_json['metadata'][key].items() if not k.startswith('volatile.'))
for k, v in self.config['config'].items(): for k, v in self.config['config'].items():
if k not in old_configs: if k not in old_configs:
@ -565,6 +577,14 @@ class LXDContainerManagement(object):
if old_configs[k] != v: if old_configs[k] != v:
return True return True
return False return False
elif key == 'config': # next default behavior
old_configs = dict((k, v) for k, v in self.old_container_json['metadata'][key].items())
for k, v in self.config['config'].items():
if k not in old_configs:
return True
if old_configs[k] != v:
return True
return False
else: else:
old_configs = self.old_container_json['metadata'][key] old_configs = self.old_container_json['metadata'][key]
return self.config[key] != old_configs return self.config[key] != old_configs
@ -606,6 +626,7 @@ class LXDContainerManagement(object):
try: try:
if self.trust_password is not None: if self.trust_password is not None:
self.client.authenticate(self.trust_password) self.client.authenticate(self.trust_password)
self.ignore_volatile_options = self.module.params.get('ignore_volatile_options')
self.old_container_json = self._get_container_json() self.old_container_json = self._get_container_json()
self.old_state = self._container_json_to_module_state(self.old_container_json) self.old_state = self._container_json_to_module_state(self.old_container_json)
@ -651,6 +672,10 @@ def main():
config=dict( config=dict(
type='dict', type='dict',
), ),
ignore_volatile_options=dict(
type='bool',
default=True
),
devices=dict( devices=dict(
type='dict', type='dict',
), ),
@ -703,7 +728,13 @@ def main():
), ),
supports_check_mode=False, supports_check_mode=False,
) )
# if module.params['ignore_volatile_options'] is None:
# module.params['ignore_volatile_options'] = True
# module.deprecate(
# 'If the keyword "volatile" is used in a playbook in the config section, a
# "changed" message will appear with every run, even without a change to the playbook.
# This will change in the future.
# Please test your scripts by "ignore_volatile_options: false"', version='5.0.0', collection_name='community.general')
lxd_manage = LXDContainerManagement(module=module) lxd_manage = LXDContainerManagement(module=module)
lxd_manage.run() lxd_manage.run()