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
186dab4d
Commit
186dab4d
authored
Feb 27, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include facter variables for free in setup JSON (prefix with 'facter'.
Also sort keys in JSON file and pretty print
parent
e766bb6a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletions
+18
-1
library/setup
+18
-1
No files found.
library/setup
View file @
186dab4d
...
@@ -5,6 +5,7 @@ DEFAULT_ANSIBLE_SETUP = "/etc/ansible/setup"
...
@@ -5,6 +5,7 @@ DEFAULT_ANSIBLE_SETUP = "/etc/ansible/setup"
import
sys
import
sys
import
os
import
os
import
shlex
import
shlex
import
subprocess
try
:
try
:
import
json
import
json
...
@@ -30,11 +31,27 @@ if not os.path.exists(ansible_file):
...
@@ -30,11 +31,27 @@ if not os.path.exists(ansible_file):
else
:
else
:
md5sum
=
os
.
popen
(
"md5sum
%
s"
%
ansible_file
)
.
read
()
md5sum
=
os
.
popen
(
"md5sum
%
s"
%
ansible_file
)
.
read
()
# 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/facter"
):
cmd
=
subprocess
.
Popen
(
"/usr/bin/facter --json"
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
cmd
.
communicate
()
facter
=
True
try
:
facter_ds
=
json
.
loads
(
out
)
except
:
facter
=
False
if
facter
:
for
(
k
,
v
)
in
facter_ds
.
items
():
new_options
[
"facter_
%
s"
%
k
]
=
v
# write the template/settings file using
# write the template/settings file using
# instructions from server
# instructions from server
f
=
open
(
ansible_file
,
"w+"
)
f
=
open
(
ansible_file
,
"w+"
)
reformat
=
json
.
dumps
(
new_options
)
reformat
=
json
.
dumps
(
new_options
,
sort_keys
=
True
,
indent
=
4
)
f
.
write
(
reformat
)
f
.
write
(
reformat
)
f
.
close
()
f
.
close
()
...
...
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