mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Adds metadata annotation that resource is managed by ansible (#44737)
Adds annotation so that other f5 utilities do not clobber config by accident
This commit is contained in:
parent
0dacc606b4
commit
d12a045847
2 changed files with 77 additions and 0 deletions
|
@ -6,8 +6,10 @@
|
|||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import copy
|
||||
import os
|
||||
import re
|
||||
import datetime
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
|
@ -26,6 +28,10 @@ except ImportError:
|
|||
HAS_F5SDK = False
|
||||
|
||||
|
||||
MANAGED_BY_ANNOTATION_VERSION = 'f5-ansible.version'
|
||||
MANAGED_BY_ANNOTATION_MODIFIED = 'f5-ansible.last_modified'
|
||||
|
||||
|
||||
f5_provider_spec = {
|
||||
'server': dict(
|
||||
fallback=(env_fallback, ['F5_SERVER'])
|
||||
|
@ -419,6 +425,56 @@ def on_bigip():
|
|||
return False
|
||||
|
||||
|
||||
def mark_managed_by(ansible_version, params):
|
||||
metadata = []
|
||||
result = copy.deepcopy(params)
|
||||
found1 = False
|
||||
found2 = False
|
||||
mark1 = dict(
|
||||
name=MANAGED_BY_ANNOTATION_VERSION,
|
||||
value=ansible_version,
|
||||
persist='true'
|
||||
)
|
||||
mark2 = dict(
|
||||
name=MANAGED_BY_ANNOTATION_MODIFIED,
|
||||
value=str(datetime.datetime.utcnow()),
|
||||
persist='true'
|
||||
)
|
||||
|
||||
if 'metadata' not in result:
|
||||
result['metadata'] = [mark1, mark2]
|
||||
return result
|
||||
|
||||
for x in params['metadata']:
|
||||
if x['name'] == MANAGED_BY_ANNOTATION_VERSION:
|
||||
found1 = True
|
||||
metadata.append(mark1)
|
||||
if x['name'] == MANAGED_BY_ANNOTATION_MODIFIED:
|
||||
found2 = True
|
||||
metadata.append(mark1)
|
||||
else:
|
||||
metadata.append(x)
|
||||
if not found1:
|
||||
metadata.append(mark1)
|
||||
if not found2:
|
||||
metadata.append(mark2)
|
||||
|
||||
result['metadata'] = metadata
|
||||
return result
|
||||
|
||||
|
||||
def only_has_managed_metadata(metadata):
|
||||
managed = [
|
||||
MANAGED_BY_ANNOTATION_MODIFIED,
|
||||
MANAGED_BY_ANNOTATION_VERSION,
|
||||
]
|
||||
|
||||
for x in metadata:
|
||||
if x['name'] not in managed:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class Noop(object):
|
||||
"""Represent no-operation required
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue