Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
27bf4d8e
Commit
27bf4d8e
authored
Mar 21, 2014
by
Brian Coca
Committed by
Michael DeHaan
Aug 08, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added getent module to get system data as facts
parent
21a0d4a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
+119
-0
library/system/getent
+119
-0
No files found.
library/system/getent
0 → 100644
View file @
27bf4d8e
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2014, Brian Coca <brian.coca+dev@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
DOCUMENTATION
=
'''
---
module: getent
short_description: a wrapper to the unix getent utility
description:
- Runs getent against one of it's various databases and returns information into the host's facts
version_added: "1.6"
options:
database:
required: True
description:
- the name of a getent database supported by the target system (passwd, group, hosts, etc).
key:
required: False
default: ''
description:
- key from which to return values from the specified database, otherwise the full contents are returned.
split:
required: False
default: None
description:
- character used to override the split the database values into lists/arrays, i.e ':' or '
\t
'.
notes: [ Not all databases support enumeration, check system documentation for details ]
requirements: [ ]
author: Brian Coca
'''
EXAMPLES
=
'''
# get root user info
- getent: database=passwd key=root split=':'
# get all groups
- getent: database=group split=':'
# get all hosts, split by tab
- getent: database=hosts
# get http service info
- getent: database=services key=http
# get user password hash (requires sudo/root)
- getent: database=shadow key=www-data split=:
'''
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
database
=
dict
(
required
=
True
),
key
=
dict
(
required
=
False
,
default
=
None
),
split
=
dict
(
required
=
False
,
default
=
None
),
),
supports_check_mode
=
True
,
)
database
=
module
.
params
[
'database'
]
key
=
module
.
params
.
get
(
'key'
)
split
=
module
.
params
.
get
(
'split'
)
getent_bin
=
module
.
get_bin_path
(
'getent'
,
True
)
if
key
is
not
None
:
cmd
=
[
getent_bin
,
database
,
key
]
else
:
cmd
=
[
getent_bin
,
database
]
try
:
rc
,
out
,
err
=
module
.
run_command
(
cmd
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
msg
=
"Unexpected failure!"
dbtree
=
'getent_
%
s'
%
database
results
=
{
dbtree
:
{}
}
if
rc
==
0
:
for
line
in
out
.
splitlines
():
record
=
line
.
split
(
split
)
results
[
dbtree
][
record
[
0
]]
=
record
[
1
:]
module
.
exit_json
(
ansible_facts
=
results
)
elif
rc
==
1
:
msg
=
"Missing arguments, or database unknown."
elif
rc
==
2
:
results
[
dbtree
][
key
]
=
None
module
.
exit_json
(
ansible_facts
=
results
,
msg
=
"One or more supplied key could not be found in the database."
)
elif
rc
==
3
:
msg
=
"Enumeration not supported on this database."
module
.
fail_json
(
msg
=
msg
)
# import module snippets
from
ansible.module_utils.basic
import
*
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment