1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

junos_user add condition when user = root (#53111)

* junos_user add condition when user = root

* Modify the failure message. Thanks NilashishC.
This commit is contained in:
linnil1 2019-03-15 01:34:47 +08:00 committed by Nilashish Chakraborty
parent 8c2037aaa9
commit e9816e10bc

View file

@ -202,11 +202,16 @@ def map_obj_to_ele(module, want):
else: else:
operation = 'merge' operation = 'merge'
if item['name'] != 'root':
user = SubElement(login, 'user', {'operation': operation}) user = SubElement(login, 'user', {'operation': operation})
SubElement(user, 'name').text = item['name'] SubElement(user, 'name').text = item['name']
else:
user = auth = SubElement(element, 'root-authentication', {'operation': operation})
if operation == 'merge': if operation == 'merge':
if item['name'] == 'root' and (not item['active'] or item['role'] or item['full_name']):
module.fail_json(msg="'root' account cannot be deactivated or be assigned a role and a full name")
if item['active']: if item['active']:
user.set('active', 'active') user.set('active', 'active')
else: else:
@ -219,6 +224,7 @@ def map_obj_to_ele(module, want):
SubElement(user, 'full-name').text = item['full_name'] SubElement(user, 'full-name').text = item['full_name']
if item.get('sshkey'): if item.get('sshkey'):
if 'auth' not in locals():
auth = SubElement(user, 'authentication') auth = SubElement(user, 'authentication')
if 'ssh-rsa' in item['sshkey']: if 'ssh-rsa' in item['sshkey']:
ssh_rsa = SubElement(auth, 'ssh-rsa') ssh_rsa = SubElement(auth, 'ssh-rsa')