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
ba6b89a5
Commit
ba6b89a5
authored
Jul 23, 2015
by
dmccue
Committed by
James Cammarata
Aug 07, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjusted output behavior
parent
0ab970da
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
contrib/inventory/cobbler.py
+13
-13
No files found.
contrib/inventory/cobbler.py
View file @
ba6b89a5
...
...
@@ -30,9 +30,10 @@ See http://ansible.github.com/api.html for more info
Tested with Cobbler 2.0.11.
Changelog:
- 2015-06-21 dmccue:
Heavily m
odified to support run-once _meta retrieval, results in
- 2015-06-21 dmccue:
M
odified to support run-once _meta retrieval, results in
higher performance at ansible startup. Groups are determined by owner rather than
default mgmt_classes. DNS name determined from hostname.
default mgmt_classes. DNS name determined from hostname. cobbler values are written
to a 'cobbler' fact namespace
- 2013-09-01 pgehres: Refactored implementation to make use of caching and to
limit the number of connections to external cobbler server for performance.
...
...
@@ -102,15 +103,14 @@ class CobblerInventory(object):
data_to_print
=
""
# Data to print
#if self.args.host:
# data_to_print = self.get_host_info()
self
.
inventory
[
'_meta'
]
=
{
'hostvars'
:
{}
}
for
hostname
in
self
.
cache
:
self
.
inventory
[
'_meta'
][
'hostvars'
][
hostname
]
=
{
'cobbler'
:
self
.
cache
[
hostname
]
}
data_to_print
=
self
.
json_format_dict
(
self
.
inventory
,
True
)
if
self
.
args
.
host
:
data_to_print
=
self
.
get_host_info
()
else
:
self
.
inventory
[
'_meta'
]
=
{
'hostvars'
:
{}
}
for
hostname
in
self
.
cache
:
self
.
inventory
[
'_meta'
][
'hostvars'
][
hostname
]
=
{
'cobbler'
:
self
.
cache
[
hostname
]
}
data_to_print
+=
self
.
json_format_dict
(
self
.
inventory
,
True
)
print
data_to_print
...
...
@@ -149,7 +149,7 @@ class CobblerInventory(object):
parser
=
argparse
.
ArgumentParser
(
description
=
'Produce an Ansible Inventory file based on Cobbler'
)
parser
.
add_argument
(
'--list'
,
action
=
'store_true'
,
default
=
True
,
help
=
'List instances (default: True)'
)
#
parser.add_argument('--host', action='store', help='Get all the variables about a specific instance')
parser
.
add_argument
(
'--host'
,
action
=
'store'
,
help
=
'Get all the variables about a specific instance'
)
parser
.
add_argument
(
'--refresh-cache'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Force refresh of cache by making API requests to cobbler (default: False - use cache files)'
)
self
.
args
=
parser
.
parse_args
()
...
...
@@ -248,7 +248,7 @@ class CobblerInventory(object):
def
write_to_cache
(
self
,
data
,
filename
):
""" Writes data in JSON format to a file """
if
data
:
print
"DEBUG: data = "
+
str
(
data
)
#
if data: print "DEBUG: data = " + str(data)
json_data
=
self
.
json_format_dict
(
data
,
True
)
cache
=
open
(
filename
,
'w'
)
cache
.
write
(
json_data
)
...
...
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