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
d0a5dec6
Commit
d0a5dec6
authored
Jul 28, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port setup module to use the common module base
parent
d79ba6f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
69 deletions
+61
-69
library/setup
+61
-69
No files found.
library/setup
View file @
d0a5dec6
...
@@ -598,73 +598,65 @@ def ansible_facts():
...
@@ -598,73 +598,65 @@ def ansible_facts():
# ===========================================
# ===========================================
# load config & template variables
def
run_setup
(
module
):
if
len
(
sys
.
argv
)
==
1
:
setup_options
=
{}
sys
.
exit
(
1
)
facts
=
ansible_facts
()
for
(
k
,
v
)
in
facts
.
items
():
argfile
=
sys
.
argv
[
1
]
setup_options
[
"ansible_
%
s"
%
k
]
=
v
if
not
os
.
path
.
exists
(
argfile
):
sys
.
exit
(
1
)
# if facter is installed, and we can use --json because
# ruby-json is ALSO installed, include facter data in the JSON
setup_options
=
open
(
argfile
)
.
read
()
.
strip
()
try
:
if
os
.
path
.
exists
(
"/usr/bin/facter"
):
setup_options
=
json
.
loads
(
setup_options
)
cmd
=
subprocess
.
Popen
(
"/usr/bin/facter --json"
,
shell
=
True
,
except
:
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
list_options
=
shlex
.
split
(
setup_options
)
out
,
err
=
cmd
.
communicate
()
setup_options
=
{}
facter
=
True
for
opt
in
list_options
:
try
:
(
k
,
v
)
=
opt
.
split
(
"="
)
facter_ds
=
json
.
loads
(
out
)
setup_options
[
k
]
=
v
except
:
facter
=
False
syslog
.
openlog
(
'ansible-
%
s'
%
os
.
path
.
basename
(
__file__
))
if
facter
:
syslog
.
syslog
(
syslog
.
LOG_NOTICE
,
'Invoked with
%
s'
%
setup_options
)
for
(
k
,
v
)
in
facter_ds
.
items
():
setup_options
[
"facter_
%
s"
%
k
]
=
v
# Get some basic facts in case facter or ohai are not installed
for
(
k
,
v
)
in
ansible_facts
()
.
items
():
# ditto for ohai, but just top level string keys
setup_options
[
"ansible_
%
s"
%
k
]
=
v
# because it contains a lot of nested stuff we can't use for
# templating w/o making a nicer key for it (TODO)
# if facter is installed, and we can use --json because
# ruby-json is ALSO installed, include facter data in the JSON
if
os
.
path
.
exists
(
"/usr/bin/ohai"
):
cmd
=
subprocess
.
Popen
(
"/usr/bin/ohai"
,
shell
=
True
,
if
os
.
path
.
exists
(
"/usr/bin/facter"
):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
cmd
=
subprocess
.
Popen
(
"/usr/bin/facter --json"
,
shell
=
True
,
out
,
err
=
cmd
.
communicate
()
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
ohai
=
True
out
,
err
=
cmd
.
communicate
()
try
:
facter
=
True
ohai_ds
=
json
.
loads
(
out
)
try
:
except
:
facter_ds
=
json
.
loads
(
out
)
ohai
=
False
except
:
if
ohai
:
facter
=
False
for
(
k
,
v
)
in
ohai_ds
.
items
():
if
facter
:
if
type
(
v
)
==
str
or
type
(
v
)
==
unicode
:
for
(
k
,
v
)
in
facter_ds
.
items
():
k2
=
"ohai_
%
s"
%
k
setup_options
[
"facter_
%
s"
%
k
]
=
v
setup_options
[
k2
]
=
v
# ditto for ohai, but just top level string keys
setup_result
=
{}
# because it contains a lot of nested stuff we can't use for
setup_result
[
'ansible_facts'
]
=
setup_options
# templating w/o making a nicer key for it (TODO)
# hack to keep --verbose from showing all the setup module results
if
os
.
path
.
exists
(
"/usr/bin/ohai"
):
setup_result
[
'verbose_override'
]
=
True
cmd
=
subprocess
.
Popen
(
"/usr/bin/ohai"
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
return
setup_result
out
,
err
=
cmd
.
communicate
()
ohai
=
True
def
main
():
try
:
module
=
AnsibleModule
(
ohai_ds
=
json
.
loads
(
out
)
argument_spec
=
dict
()
except
:
)
ohai
=
False
data
=
run_setup
(
module
)
if
ohai
:
module
.
exit_json
(
**
data
)
for
(
k
,
v
)
in
ohai_ds
.
items
():
if
type
(
v
)
==
str
or
type
(
v
)
==
unicode
:
# this is magic, see lib/ansible/module_common.py
k2
=
"ohai_
%
s"
%
k
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
setup_options
[
k2
]
=
v
main
()
setup_result
=
{}
setup_result
[
'ansible_facts'
]
=
setup_options
# hack to keep --verbose from showing all the setup module results
setup_result
[
'verbose_override'
]
=
True
print
json
.
dumps
(
setup_result
)
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