getent - add service support(#60295)

pull/61395/head
ygelfand 5 years ago committed by Sam Doran
parent c91929b2b3
commit 36b7baca4d

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

@ -30,6 +30,11 @@ options:
- Key from which to return values from the specified database, otherwise the - Key from which to return values from the specified database, otherwise the
full contents are returned. full contents are returned.
default: '' 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: split:
description: 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." - "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( argument_spec=dict(
database=dict(type='str', required=True), database=dict(type='str', required=True),
key=dict(type='str'), key=dict(type='str'),
service=dict(type='str'),
split=dict(type='str'), split=dict(type='str'),
fail_key=dict(type='bool', default=True), fail_key=dict(type='bool', default=True),
), ),
@ -105,6 +111,7 @@ def main():
database = module.params['database'] database = module.params['database']
key = module.params.get('key') key = module.params.get('key')
split = module.params.get('split') split = module.params.get('split')
service = module.params.get('service')
fail_key = module.params.get('fail_key') fail_key = module.params.get('fail_key')
getent_bin = module.get_bin_path('getent', True) getent_bin = module.get_bin_path('getent', True)
@ -114,6 +121,9 @@ def main():
else: else:
cmd = [getent_bin, database] cmd = [getent_bin, database]
if service is not None:
cmd.extend(['-s', service])
if split is None and database in colon: if split is None and database in colon:
split = ':' split = ':'

@ -23,11 +23,19 @@
## getent ## getent
## ##
- block: - block:
- name: run the first example - name: run getent with specified service
getent: getent:
database: passwd database: passwd
key: root key: root
service: files
register: getent_test0 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 - debug: var=getent_test0
- name: validate results - name: validate results
assert: assert:

Loading…
Cancel
Save