mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 20:30:46 -03:30
Remove the cred too if not passed
NOW....should be idempotent and remove the the cred if it is not passed
This commit is contained in:
parent
e2b0a4f7a7
commit
f2dac36dd1
@ -68,23 +68,28 @@ class Command(BaseCommand):
|
||||
sys.stderr.write("No registry credential type found")
|
||||
sys.exit(1)
|
||||
|
||||
registry_cred, cred_created = Credential.objects.get_or_create(
|
||||
name="Default Execution Environment Registry Credential", managed_by_tower=True, credential_type=registry_cred_type[0]
|
||||
)
|
||||
|
||||
if cred_created:
|
||||
print("'Default Execution Environment Credential' registered.")
|
||||
|
||||
inputs = {
|
||||
"host": options.get("registry_url"),
|
||||
"password": options.get("registry_password"),
|
||||
"username": options.get("registry_username"),
|
||||
"verify_ssl": options.get("verify_ssl"),
|
||||
}
|
||||
registry_cred, cred_created = Credential.objects.get_or_create(
|
||||
name="Default Execution Environment Registry Credential",
|
||||
managed_by_tower=True,
|
||||
credential_type=registry_cred_type[0],
|
||||
defaults={'inputs': inputs},
|
||||
)
|
||||
|
||||
if cred_created:
|
||||
changed = True
|
||||
print("'Default Execution Environment Credential' registered.")
|
||||
|
||||
for key, value in inputs.items():
|
||||
if registry_cred.get_input(key) != value:
|
||||
if not registry_cred.inputs.get(key) or registry_cred.get_input(key) != value:
|
||||
registry_cred.inputs[key] = value
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
registry_cred.save()
|
||||
print("'Default Execution Environment Credential' updated.")
|
||||
@ -95,27 +100,34 @@ class Command(BaseCommand):
|
||||
if ee_created:
|
||||
changed = True
|
||||
print(f"'{ee['name']}' Default Execution Environment registered.")
|
||||
elif _this_ee.image != ee["image"] or (registry_cred and _this_ee.credential_id != registry_cred.id):
|
||||
_this_ee.image = ee["image"]
|
||||
_this_ee.credential = registry_cred
|
||||
else:
|
||||
if _this_ee.image != ee["image"]:
|
||||
_this_ee.image = ee["image"]
|
||||
changed = True
|
||||
if _this_ee.credential != registry_cred:
|
||||
_this_ee.credential = registry_cred
|
||||
changed = True
|
||||
if changed:
|
||||
_this_ee.save()
|
||||
changed = True
|
||||
print(f"'{ee['name']}' Default Execution Environment updated.")
|
||||
|
||||
# Create the control plane execution environment that is used for project updates and system jobs
|
||||
control_plane_ee_image = settings.CONTROL_PLANE_EXECUTION_ENVIRONMENT
|
||||
_cp_ee, cp_created = ExecutionEnvironment.objects.get_or_create(
|
||||
name="Control Plane Execution Environment", defaults={'image': control_plane_ee_image, 'managed_by_tower': True, 'credential': registry_cred}
|
||||
ee = settings.CONTROL_PLANE_EXECUTION_ENVIRONMENT
|
||||
_this_ee, cp_created = ExecutionEnvironment.objects.get_or_create(
|
||||
name="Control Plane Execution Environment", defaults={'image': ee, 'managed_by_tower': True, 'credential': registry_cred}
|
||||
)
|
||||
if cp_created:
|
||||
changed = True
|
||||
print("Control Plane Execution Environment registered.")
|
||||
elif _cp_ee.image != control_plane_ee_image or (registry_cred and _cp_ee.credential_id != registry_cred.id):
|
||||
_cp_ee.image = control_plane_ee_image
|
||||
_cp_ee.credential = registry_cred
|
||||
_cp_ee.save()
|
||||
changed = True
|
||||
print("Control Plane Execution Environment updated.")
|
||||
else:
|
||||
if _this_ee.image != ee:
|
||||
_this_ee.image = ee
|
||||
changed = True
|
||||
if _this_ee.credential != registry_cred:
|
||||
_this_ee.credential = registry_cred
|
||||
changed = True
|
||||
if changed:
|
||||
_this_ee.save()
|
||||
|
||||
if changed:
|
||||
print("(changed: True)")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user