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
c56a304a
Commit
c56a304a
authored
Jul 26, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9195 from reedloden/add-dns-facts
Add several DNS-related facts by parsing /etc/resolv.conf
parents
ccb7fb3b
eb1fb415
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
lib/ansible/module_utils/facts.py
+32
-0
No files found.
lib/ansible/module_utils/facts.py
View file @
c56a304a
...
...
@@ -151,6 +151,7 @@ class Facts(object):
self
.
get_user_facts
()
self
.
get_local_facts
()
self
.
get_env_facts
()
self
.
get_dns_facts
()
def
populate
(
self
):
return
self
.
facts
...
...
@@ -632,6 +633,37 @@ class Facts(object):
for
k
,
v
in
os
.
environ
.
iteritems
():
self
.
facts
[
'env'
][
k
]
=
v
def
get_dns_facts
(
self
):
self
.
facts
[
'dns'
]
=
{}
for
line
in
get_file_lines
(
'/etc/resolv.conf'
):
if
line
.
startswith
(
'#'
)
or
line
.
startswith
(
';'
)
or
line
.
strip
()
==
''
:
continue
tokens
=
line
.
split
()
if
len
(
tokens
)
==
0
:
continue
if
tokens
[
0
]
==
'nameserver'
:
self
.
facts
[
'dns'
][
'nameservers'
]
=
[]
for
nameserver
in
tokens
[
1
:]:
self
.
facts
[
'dns'
][
'nameservers'
]
.
append
(
nameserver
)
elif
tokens
[
0
]
==
'domain'
:
self
.
facts
[
'dns'
][
'domain'
]
=
tokens
[
1
]
elif
tokens
[
0
]
==
'search'
:
self
.
facts
[
'dns'
][
'search'
]
=
[]
for
suffix
in
tokens
[
1
:]:
self
.
facts
[
'dns'
][
'search'
]
.
append
(
suffix
)
elif
tokens
[
0
]
==
'sortlist'
:
self
.
facts
[
'dns'
][
'sortlist'
]
=
[]
for
address
in
tokens
[
1
:]:
self
.
facts
[
'dns'
][
'sortlist'
]
.
append
(
address
)
elif
tokens
[
0
]
==
'options'
:
self
.
facts
[
'dns'
][
'options'
]
=
{}
for
option
in
tokens
[
1
:]:
option_tokens
=
option
.
split
(
':'
,
1
)
if
len
(
option_tokens
)
==
0
:
continue
val
=
len
(
option_tokens
)
==
2
and
option_tokens
[
1
]
or
True
self
.
facts
[
'dns'
][
'options'
][
option_tokens
[
0
]]
=
val
class
Hardware
(
Facts
):
"""
This is a generic Hardware subclass of Facts. This should be further
...
...
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