Merge pull request #310 from t-woerner/fail_on_duplicate_names

ipa[user,host]: Fail on duplucate names in the users and hosts lists
This commit is contained in:
Thomas Woerner
2020-06-29 18:52:13 +02:00
committed by GitHub
4 changed files with 48 additions and 0 deletions

View File

@@ -799,10 +799,15 @@ def main():
server_realm = api_get_realm() server_realm = api_get_realm()
commands = [] commands = []
host_set = set()
for host in names: for host in names:
if isinstance(host, dict): if isinstance(host, dict):
name = host.get("name") name = host.get("name")
if name in host_set:
ansible_module.fail_json(
msg="host '%s' is used more than once" % name)
host_set.add(name)
description = host.get("description") description = host.get("description")
locality = host.get("locality") locality = host.get("locality")
location = host.get("location") location = host.get("location")
@@ -1337,6 +1342,8 @@ def main():
else: else:
ansible_module.fail_json(msg="Unkown state '%s'" % state) ansible_module.fail_json(msg="Unkown state '%s'" % state)
del host_set
# Execute commands # Execute commands
errors = [] errors = []

View File

@@ -958,10 +958,15 @@ def main():
# commands # commands
commands = [] commands = []
user_set = set()
for user in names: for user in names:
if isinstance(user, dict): if isinstance(user, dict):
name = user.get("name") name = user.get("name")
if name in user_set:
ansible_module.fail_json(
msg="user '%s' is used more than once" % name)
user_set.add(name)
# present # present
first = user.get("first") first = user.get("first")
last = user.get("last") last = user.get("last")
@@ -1370,6 +1375,8 @@ def main():
else: else:
ansible_module.fail_json(msg="Unkown state '%s'" % state) ansible_module.fail_json(msg="Unkown state '%s'" % state)
del user_set
# Execute commands # Execute commands
errors = [] errors = []

View File

@@ -96,3 +96,18 @@
state: absent state: absent
register: result register: result
failed_when: result.changed failed_when: result.changed
- name: Duplicate names in hosts failure test
ipahost:
ipaadmin_password: SomeADMINpassword
hosts:
- name: "{{ host1_fqdn }}"
force: yes
- name: "{{ host2_fqdn }}"
force: yes
- name: "{{ host3_fqdn }}"
force: yes
- name: "{{ host3_fqdn }}"
force: yes
register: result
failed_when: result.changed or "is used more than once" not in result.msg

View File

@@ -85,6 +85,25 @@
register: result register: result
failed_when: result.changed failed_when: result.changed
- name: Duplicate names in users failure test
ipauser:
ipaadmin_password: SomeADMINpassword
users:
- name: user1
givenname: user1
last: Last
- name: user2
first: user2
last: Last
- name: user3
first: user3
last: Last
- name: user3
first: user3
last: Last
register: result
failed_when: result.changed or "is used more than once" not in result.msg
- name: Remove test users - name: Remove test users
ipauser: ipauser:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword