Skip to content
Snippets Groups Projects
Unverified Commit e681f25e authored by Rafael Guterres Jeffman's avatar Rafael Guterres Jeffman Committed by GitHub
Browse files

Merge pull request #773 from...

Merge pull request #773 from t-woerner/servicedelegation_do_no_fail_on_not_existing_members_with_state_absent

servicedelegation: Do not fail for not existing members with state absent
parents 892cb037 8010d19b
Branches
Tags
No related merge requests found
...@@ -551,7 +551,8 @@ else: ...@@ -551,7 +551,8 @@ else:
return False return False
return True return True
def servicedelegation_normalize_principals(module, principal): def servicedelegation_normalize_principals(module, principal,
check_exists=False):
""" """
Normalize servicedelegation principals. Normalize servicedelegation principals.
...@@ -620,12 +621,13 @@ else: ...@@ -620,12 +621,13 @@ else:
_host = _host[:-len(realm) - 1] _host = _host[:-len(realm) - 1]
# Seach for host # Seach for host
if not _check_exists(module, "host", _host): if check_exists and not _check_exists(module, "host", _host):
module.fail_json(msg="Host '%s' does not exist" % _host) module.fail_json(msg="Host '%s' does not exist" % _host)
# Check the service principal exists # Check the service principal exists
else: else:
if not _check_exists(module, "service", princ): if check_exists and \
not _check_exists(module, "service", princ):
module.fail_json(msg="Service %s does not exist" % princ) module.fail_json(msg="Service %s does not exist" % princ)
_principal.append(princ) _principal.append(princ)
......
...@@ -221,9 +221,9 @@ def main(): ...@@ -221,9 +221,9 @@ def main():
# Normalize principals # Normalize principals
if principal: if principal:
principal = servicedelegation_normalize_principals(ansible_module, principal = servicedelegation_normalize_principals(
principal) ansible_module, principal, state == "present")
if target: if target and state == "present":
check_targets(ansible_module, target) check_targets(ansible_module, target)
commands = [] commands = []
......
...@@ -177,8 +177,8 @@ def main(): ...@@ -177,8 +177,8 @@ def main():
# Normalize principals # Normalize principals
if principal: if principal:
principal = servicedelegation_normalize_principals(ansible_module, principal = servicedelegation_normalize_principals(
principal) ansible_module, principal, state == "present")
commands = [] commands = []
principal_add = principal_del = [] principal_add = principal_del = []
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
ipaservice: ipaservice:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}" ipaapi_context: "{{ ipa_context | default(omit) }}"
name: "{{ 'test-service/' + ansible_facts['fqdn'] }}" name:
- "{{ 'test-service/' + ansible_facts['fqdn'] }}"
- "{{ 'not-existing-test-service/' + ansible_facts['fqdn'] }}"
state: absent state: absent
continue: yes continue: yes
...@@ -29,7 +31,9 @@ ...@@ -29,7 +31,9 @@
ipaservicedelegationtarget: ipaservicedelegationtarget:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}" ipaapi_context: "{{ ipa_context | default(omit) }}"
name: test-delegation-target name:
- test-delegation-target
- not-existing-test-delegation-target
state: absent state: absent
# CREATE TEST ITEMS # CREATE TEST ITEMS
...@@ -68,6 +72,28 @@ ...@@ -68,6 +72,28 @@
register: result register: result
failed_when: result.changed or result.failed failed_when: result.changed or result.failed
- name: Do not fail to ensure absence of not existing servicedelegationrule test-delegation-rule member principal
ipaservicedelegationrule:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: test-delegation-rule
principal: "{{ 'not-existing-test-service/' + ansible_facts['fqdn'] }}"
action: member
state: absent
register: result
failed_when: result.changed or result.failed
- name: Do not fail to ensure absence of not existing servicedelegationrule test-delegation-rule member target
ipaservicedelegationrule:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: test-delegation-rule
target: not-existing-test-delegation-target
action: member
state: absent
register: result
failed_when: result.changed or result.failed
- name: Ensure servicedelegationrule test-delegation-rule member target test-delegation-target is present - name: Ensure servicedelegationrule test-delegation-rule member target test-delegation-target is present
ipaservicedelegationrule: ipaservicedelegationrule:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
- "{{ 'test-service1/' + ansible_facts['fqdn'] }}" - "{{ 'test-service1/' + ansible_facts['fqdn'] }}"
- "{{ 'test-service2/' + ansible_facts['fqdn'] }}" - "{{ 'test-service2/' + ansible_facts['fqdn'] }}"
- "{{ 'test-service3/' + ansible_facts['fqdn'] }}" - "{{ 'test-service3/' + ansible_facts['fqdn'] }}"
- "{{ 'not-existing-test-service/' + ansible_facts['fqdn'] }}"
state: absent state: absent
continue: yes continue: yes
...@@ -72,6 +73,17 @@ ...@@ -72,6 +73,17 @@
register: result register: result
failed_when: result.changed or result.failed failed_when: result.changed or result.failed
- name: Do not fail to ensure absence of not existing servicedelegationtarget test-delegation-target member principal
ipaservicedelegationtarget:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: test-delegation-target
principal: "{{ 'not-existing-test-service/' + ansible_facts['fqdn'] }}"
action: member
state: absent
register: result
failed_when: result.changed or result.failed
- name: Ensure servicedelegationtarget test-delegation-target member principal "{{ 'test-service1/' + ansible_facts['fqdn'] }}" is present - name: Ensure servicedelegationtarget test-delegation-target member principal "{{ 'test-service1/' + ansible_facts['fqdn'] }}" is present
ipaservicedelegationtarget: ipaservicedelegationtarget:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment