getent - add service support(#60295)

This commit is contained in:
ygelfand 2019-08-27 11:58:37 -04:00 committed by Sam Doran
parent c91929b2b3
commit 36b7baca4d
3 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- getent - add service parameter to getent to lookup specified service

View file

@ -30,6 +30,11 @@ options:
- Key from which to return values from the specified database, otherwise the
full contents are returned.
default: ''
service:
description:
- Override all databases with the specified service
- The underlying system must support the service flag which is not always available.
version_added: "2.9"
split:
description:
- "Character used to split the database values into lists/arrays such as ':' or '\t', otherwise it will try to pick one depending on the database."
@ -94,6 +99,7 @@ def main():
argument_spec=dict(
database=dict(type='str', required=True),
key=dict(type='str'),
service=dict(type='str'),
split=dict(type='str'),
fail_key=dict(type='bool', default=True),
),
@ -105,6 +111,7 @@ def main():
database = module.params['database']
key = module.params.get('key')
split = module.params.get('split')
service = module.params.get('service')
fail_key = module.params.get('fail_key')
getent_bin = module.get_bin_path('getent', True)
@ -114,6 +121,9 @@ def main():
else:
cmd = [getent_bin, database]
if service is not None:
cmd.extend(['-s', service])
if split is None and database in colon:
split = ':'

View file

@ -23,11 +23,19 @@
## getent
##
- block:
- name: run the first example
- name: run getent with specified service
getent:
database: passwd
key: root
service: files
register: getent_test0
when: ansible_system != 'FreeBSD'
- name: run getent w/o specified service (FreeBSD)
getent:
database: passwd
key: root
register: getent_test0
when: ansible_system == 'FreeBSD'
- debug: var=getent_test0
- name: validate results
assert: