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
4b89eb29
Commit
4b89eb29
authored
Jan 30, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
port fix for
https://github.com/ansible/ansible/pull/10129
to v2
parent
ca35d138
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
2 deletions
+54
-2
v2/ansible/module_utils/facts.py
+54
-2
No files found.
v2/ansible/module_utils/facts.py
View file @
4b89eb29
...
...
@@ -29,6 +29,7 @@ import socket
import
struct
import
datetime
import
getpass
import
pwd
import
ConfigParser
import
StringIO
...
...
@@ -551,6 +552,12 @@ class Facts(object):
# User
def
get_user_facts
(
self
):
self
.
facts
[
'user_id'
]
=
getpass
.
getuser
()
pwent
=
pwd
.
getpwnam
(
getpass
.
getuser
())
self
.
facts
[
'user_uid'
]
=
pwent
.
pw_uid
self
.
facts
[
'user_gid'
]
=
pwent
.
pw_gid
self
.
facts
[
'user_gecos'
]
=
pwent
.
pw_gecos
self
.
facts
[
'user_dir'
]
=
pwent
.
pw_dir
self
.
facts
[
'user_shell'
]
=
pwent
.
pw_shell
def
get_env_facts
(
self
):
self
.
facts
[
'env'
]
=
{}
...
...
@@ -602,7 +609,11 @@ class LinuxHardware(Hardware):
"""
platform
=
'Linux'
MEMORY_FACTS
=
[
'MemTotal'
,
'SwapTotal'
,
'MemFree'
,
'SwapFree'
]
# Originally only had these four as toplevelfacts
ORIGINAL_MEMORY_FACTS
=
frozenset
((
'MemTotal'
,
'SwapTotal'
,
'MemFree'
,
'SwapFree'
))
# Now we have all of these in a dict structure
MEMORY_FACTS
=
ORIGINAL_MEMORY_FACTS
.
union
((
'Buffers'
,
'Cached'
,
'SwapCached'
))
def
__init__
(
self
):
Hardware
.
__init__
(
self
)
...
...
@@ -621,13 +632,46 @@ class LinuxHardware(Hardware):
def
get_memory_facts
(
self
):
if
not
os
.
access
(
"/proc/meminfo"
,
os
.
R_OK
):
return
memstats
=
{}
for
line
in
open
(
"/proc/meminfo"
)
.
readlines
():
data
=
line
.
split
(
":"
,
1
)
key
=
data
[
0
]
if
key
in
LinuxHardware
.
MEMORY_FACTS
:
if
key
in
self
.
ORIGINAL_
MEMORY_FACTS
:
val
=
data
[
1
]
.
strip
()
.
split
(
' '
)[
0
]
self
.
facts
[
"
%
s_mb"
%
key
.
lower
()]
=
long
(
val
)
/
1024
if
key
in
self
.
MEMORY_FACTS
:
val
=
data
[
1
]
.
strip
()
.
split
(
' '
)[
0
]
memstats
[
key
.
lower
()]
=
long
(
val
)
/
1024
if
None
not
in
(
memstats
.
get
(
'memtotal'
),
memstats
.
get
(
'memfree'
)):
memstats
[
'real:used'
]
=
memstats
[
'memtotal'
]
-
memstats
[
'memfree'
]
if
None
not
in
(
memstats
.
get
(
'cached'
),
memstats
.
get
(
'memfree'
),
memstats
.
get
(
'buffers'
)):
memstats
[
'nocache:free'
]
=
memstats
[
'cached'
]
+
memstats
[
'memfree'
]
+
memstats
[
'buffers'
]
if
None
not
in
(
memstats
.
get
(
'memtotal'
),
memstats
.
get
(
'nocache:free'
)):
memstats
[
'nocache:used'
]
=
memstats
[
'memtotal'
]
-
memstats
[
'nocache:free'
]
if
None
not
in
(
memstats
.
get
(
'swaptotal'
),
memstats
.
get
(
'swapfree'
)):
memstats
[
'swap:used'
]
=
memstats
[
'swaptotal'
]
-
memstats
[
'swapfree'
]
self
.
facts
[
'memory_mb'
]
=
{
'real'
:
{
'total'
:
memstats
.
get
(
'memtotal'
),
'used'
:
memstats
.
get
(
'real:used'
),
'free'
:
memstats
.
get
(
'memfree'
),
},
'nocache'
:
{
'free'
:
memstats
.
get
(
'nocache:free'
),
'used'
:
memstats
.
get
(
'nocache:used'
),
},
'swap'
:
{
'total'
:
memstats
.
get
(
'swaptotal'
),
'free'
:
memstats
.
get
(
'swapfree'
),
'used'
:
memstats
.
get
(
'swap:used'
),
'cached'
:
memstats
.
get
(
'swapcached'
),
},
}
def
get_cpu_facts
(
self
):
i
=
0
vendor_id_occurrence
=
0
...
...
@@ -795,6 +839,13 @@ class LinuxHardware(Hardware):
size_available
=
statvfs_result
.
f_bsize
*
(
statvfs_result
.
f_bavail
)
except
OSError
,
e
:
continue
lsblkPath
=
module
.
get_bin_path
(
"lsblk"
)
rc
,
out
,
err
=
module
.
run_command
(
"
%
s -ln --output UUID
%
s"
%
(
lsblkPath
,
fields
[
0
]),
use_unsafe_shell
=
True
)
if
rc
==
0
:
uuid
=
out
.
strip
()
else
:
uuid
=
'NA'
self
.
facts
[
'mounts'
]
.
append
(
{
'mount'
:
fields
[
1
],
...
...
@@ -804,6 +855,7 @@ class LinuxHardware(Hardware):
# statvfs data
'size_total'
:
size_total
,
'size_available'
:
size_available
,
'uuid'
:
uuid
,
})
def
get_device_facts
(
self
):
...
...
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