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
d2c49db0
Commit
d2c49db0
authored
Jan 20, 2015
by
Erinn Looney-Triggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup and expand FreeIPA inventory script it now accepts CL
parameters.
parent
e6b5cc9c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
15 deletions
+75
-15
plugins/inventory/freeipa.py
+75
-15
No files found.
plugins/inventory/freeipa.py
View file @
d2c49db0
#!/usr/bin/env python
import
json
import
argparse
from
ipalib
import
api
api
.
bootstrap
(
context
=
'cli'
)
api
.
finalize
()
api
.
Backend
.
xmlclient
.
connect
()
inventory
=
{}
hostvars
=
{}
meta
=
{}
result
=
api
.
Command
.
hostgroup_find
()[
'result'
]
for
hostgroup
in
result
:
inventory
[
hostgroup
[
'cn'
][
0
]]
=
{
'hosts'
:
[
host
for
host
in
hostgroup
[
'member_host'
]]}
for
host
in
hostgroup
[
'member_host'
]:
hostvars
[
host
]
=
{}
inventory
[
'_meta'
]
=
{
'hostvars'
:
hostvars
}
inv_string
=
json
.
dumps
(
inventory
)
print
inv_string
import
json
def
initialize
():
'''
This function initializes the FreeIPA/IPA API. This function requires
no arguments. A kerberos key must be present in the users keyring in
order for this to work.
'''
api
.
bootstrap
(
context
=
'cli'
)
api
.
finalize
()
api
.
Backend
.
xmlclient
.
connect
()
return
api
def
list_groups
(
api
):
'''
This function returns a list of all host groups. This function requires
one argument, the FreeIPA/IPA API object.
'''
inventory
=
{}
hostvars
=
{}
meta
=
{}
result
=
api
.
Command
.
hostgroup_find
()[
'result'
]
for
hostgroup
in
result
:
inventory
[
hostgroup
[
'cn'
][
0
]]
=
{
'hosts'
:
[
host
for
host
in
hostgroup
[
'member_host'
]]}
for
host
in
hostgroup
[
'member_host'
]:
hostvars
[
host
]
=
{}
inventory
[
'_meta'
]
=
{
'hostvars'
:
hostvars
}
inv_string
=
json
.
dumps
(
inventory
,
indent
=
1
,
sort_keys
=
True
)
print
inv_string
return
None
def
parse_args
():
'''
This function parses the arguments that were passed in via the command line.
This function expects no arguments.
'''
parser
=
argparse
.
ArgumentParser
(
description
=
'Ansible FreeIPA/IPA '
'inventory module'
)
group
=
parser
.
add_mutually_exclusive_group
(
required
=
True
)
group
.
add_argument
(
'--list'
,
action
=
'store_true'
,
help
=
'List active servers'
)
group
.
add_argument
(
'--host'
,
help
=
'List details about the specified host'
)
return
parser
.
parse_args
()
def
print_host
(
host
):
'''
This function is really a stub, it could return variables to be used in
a playbook. However, at this point there are no variables stored in
FreeIPA/IPA.
This function expects one string, this hostname to lookup variables for.
'''
print
json
.
dumps
({})
return
None
if
__name__
==
'__main__'
:
args
=
parse_args
()
if
args
.
host
:
print_host
(
args
.
host
)
elif
args
.
list
:
api
=
initialize
()
list_groups
(
api
)
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