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
4ecaa78c
Commit
4ecaa78c
authored
Nov 28, 2014
by
Andrew Rothstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
incorporated code review feedback
parent
fbc1cd55
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
plugins/inventory/fleet.py
+6
-6
No files found.
plugins/inventory/fleet.py
View file @
4ecaa78c
...
@@ -39,7 +39,7 @@ except:
...
@@ -39,7 +39,7 @@ except:
parser
=
OptionParser
(
usage
=
"
%
prog [options] --list | --host <machine>"
)
parser
=
OptionParser
(
usage
=
"
%
prog [options] --list | --host <machine>"
)
parser
.
add_option
(
'--list'
,
default
=
False
,
dest
=
"list"
,
action
=
"store_true"
,
parser
.
add_option
(
'--list'
,
default
=
False
,
dest
=
"list"
,
action
=
"store_true"
,
help
=
"Produce a JSON consumable grouping of
Vagrant servers for Ansible
"
)
help
=
"Produce a JSON consumable grouping of
servers in your fleet
"
)
parser
.
add_option
(
'--host'
,
default
=
None
,
dest
=
"host"
,
parser
.
add_option
(
'--host'
,
default
=
None
,
dest
=
"host"
,
help
=
"Generate additional host specific details for given host for Ansible"
)
help
=
"Generate additional host specific details for given host for Ansible"
)
(
options
,
args
)
=
parser
.
parse_args
()
(
options
,
args
)
=
parser
.
parse_args
()
...
@@ -48,9 +48,9 @@ parser.add_option('--host', default=None, dest="host",
...
@@ -48,9 +48,9 @@ parser.add_option('--host', default=None, dest="host",
# helper functions
# helper functions
#
#
def
get_ssh_config
()
:
def
get_ssh_config
():
configs
=
[]
configs
=
[]
for
box
in
list_running_boxes
()
:
for
box
in
list_running_boxes
():
config
=
get_a_ssh_config
(
box
)
config
=
get_a_ssh_config
(
box
)
configs
.
append
(
config
)
configs
.
append
(
config
)
return
configs
return
configs
...
@@ -58,14 +58,14 @@ def get_ssh_config() :
...
@@ -58,14 +58,14 @@ def get_ssh_config() :
#list all the running instances in the fleet
#list all the running instances in the fleet
def
list_running_boxes
():
def
list_running_boxes
():
boxes
=
[]
boxes
=
[]
for
line
in
subprocess
.
check_output
([
"fleetctl"
,
"list-machines"
])
.
split
(
'
\n
'
)
:
for
line
in
subprocess
.
check_output
([
"fleetctl"
,
"list-machines"
])
.
split
(
'
\n
'
):
matcher
=
re
.
search
(
"[^
\
s]+[
\
s]+([^
\
s]+).+"
,
line
)
matcher
=
re
.
search
(
"[^
\
s]+[
\
s]+([^
\
s]+).+"
,
line
)
if
matcher
and
matcher
.
group
(
1
)
!=
"IP"
:
if
matcher
and
matcher
.
group
(
1
)
!=
"IP"
:
boxes
.
append
(
matcher
.
group
(
1
))
boxes
.
append
(
matcher
.
group
(
1
))
return
boxes
return
boxes
def
get_a_ssh_config
(
box_name
)
:
def
get_a_ssh_config
(
box_name
):
config
=
{}
config
=
{}
config
[
'Host'
]
=
box_name
config
[
'Host'
]
=
box_name
config
[
'ansible_ssh_user'
]
=
'core'
config
[
'ansible_ssh_user'
]
=
'core'
...
@@ -78,7 +78,7 @@ if options.list:
...
@@ -78,7 +78,7 @@ if options.list:
ssh_config
=
get_ssh_config
()
ssh_config
=
get_ssh_config
()
hosts
=
{
'coreos'
:
[]}
hosts
=
{
'coreos'
:
[]}
for
data
in
ssh_config
:
for
data
in
ssh_config
:
hosts
[
'coreos'
]
.
append
(
data
[
'Host'
])
hosts
[
'coreos'
]
.
append
(
data
[
'Host'
])
print
json
.
dumps
(
hosts
)
print
json
.
dumps
(
hosts
)
...
...
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