mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudstack: fix user data unexpected marked as changed (#20540)
self.instance may be overwritten before the user data comparsion which result in a false positive changed state. With this commit, we make sure we have the userdata when we need to.
This commit is contained in:
parent
ebe621bb23
commit
d1c3cbbc70
1 changed files with 14 additions and 4 deletions
|
@ -533,15 +533,23 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
|||
if not vpc_id and self.is_vm_in_vpc(vm=v):
|
||||
continue
|
||||
if instance_name.lower() in [ v['name'].lower(), v['displayname'].lower(), v['id'] ]:
|
||||
# Query the user data if we need to
|
||||
if 'userdata' not in v and self.get_user_data() is not None:
|
||||
res = self.cs.getVirtualMachineUserData(virtualmachineid=v['id'])
|
||||
v['userdata'] = res['virtualmachineuserdata'].get('userdata',"")
|
||||
self.instance = v
|
||||
break
|
||||
return self.instance
|
||||
|
||||
|
||||
def _get_instance_user_data(self, instance):
|
||||
# Query the user data if we need to
|
||||
if 'userdata' in instance:
|
||||
return instance['userdata']
|
||||
|
||||
user_data = ""
|
||||
if self.get_user_data() is not None:
|
||||
res = self.cs.getVirtualMachineUserData(virtualmachineid=instance['id'])
|
||||
user_data = res['virtualmachineuserdata'].get('userdata',"")
|
||||
return user_data
|
||||
|
||||
|
||||
def get_iptonetwork_mappings(self):
|
||||
network_mappings = self.module.params.get('ip_to_networks')
|
||||
if network_mappings is None:
|
||||
|
@ -738,6 +746,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
|||
args_instance_update = {}
|
||||
args_instance_update['id'] = instance['id']
|
||||
args_instance_update['userdata'] = self.get_user_data()
|
||||
instance['userdata'] = self._get_instance_user_data(instance)
|
||||
args_instance_update['ostypeid'] = self.get_os_type(key='id')
|
||||
if self.module.params.get('group'):
|
||||
args_instance_update['group'] = self.module.params.get('group')
|
||||
|
@ -941,6 +950,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
|||
def get_result(self, instance):
|
||||
super(AnsibleCloudStackInstance, self).get_result(instance)
|
||||
if instance:
|
||||
self.result['user_data'] = self._get_instance_user_data(instance)
|
||||
if 'securitygroup' in instance:
|
||||
security_groups = []
|
||||
for securitygroup in instance['securitygroup']:
|
||||
|
|
Loading…
Reference in a new issue