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
5730a298
Commit
5730a298
authored
May 05, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
missing files
parent
0669ce85
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
0 deletions
+137
-0
lib/ansible/group.py
+75
-0
lib/ansible/host.py
+62
-0
No files found.
lib/ansible/group.py
0 → 100644
View file @
5730a298
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#############################################
# from ansible import errors
class
Group
(
object
):
"""
Group of ansible hosts
"""
def
__init__
(
self
,
name
=
None
):
self
.
name
=
name
self
.
hosts
=
[]
self
.
vars
=
{}
self
.
child_groups
=
[]
self
.
parent_groups
=
[]
if
self
.
name
is
None
:
raise
Exception
(
"group name is required"
)
def
add_child_group
(
self
,
group
):
if
self
==
group
:
raise
Exception
(
"can't add group to itself"
)
self
.
child_groups
.
append
(
group
)
group
.
parent_groups
.
append
(
self
)
def
add_host
(
self
,
host
):
self
.
hosts
.
append
(
host
)
host
.
add_group
(
self
)
def
set_variable
(
self
,
key
,
value
):
self
.
vars
[
key
]
=
value
def
get_hosts
(
self
):
hosts
=
[]
for
kid
in
self
.
child_groups
:
hosts
.
extend
(
kid
.
get_hosts
())
hosts
.
extend
(
self
.
hosts
)
return
hosts
def
get_variables
(
self
):
vars
=
{}
# FIXME: verify this variable override order is what we want
for
ancestor
in
self
.
get_ancestors
():
vars
.
update
(
ancestor
.
get_variables
())
vars
.
update
(
self
.
vars
)
return
vars
def
_get_ancestors
(
self
):
results
=
{}
for
g
in
self
.
parent_groups
:
results
[
g
.
name
]
=
g
results
.
update
(
g
.
_get_ancestors
())
return
results
def
get_ancestors
(
self
):
return
self
.
_get_ancestors
()
.
values
()
lib/ansible/host.py
0 → 100644
View file @
5730a298
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#############################################
from
ansible
import
errors
import
ansible.constants
as
C
class
Host
(
object
):
"""
Group of ansible hosts
"""
def
__init__
(
self
,
name
=
None
,
port
=
None
):
self
.
name
=
name
self
.
vars
=
{}
self
.
groups
=
[]
if
port
and
port
!=
C
.
DEFAULT_REMOTE_PORT
:
self
.
set_variable
(
'ansible_ssh_port'
,
int
(
port
))
if
self
.
name
is
None
:
raise
Exception
(
"host name is required"
)
def
add_group
(
self
,
group
):
self
.
groups
.
append
(
group
)
def
set_variable
(
self
,
key
,
value
):
self
.
vars
[
key
]
=
value
;
def
get_groups
(
self
):
groups
=
{}
for
g
in
self
.
groups
:
groups
[
g
.
name
]
=
g
ancestors
=
g
.
get_ancestors
()
for
a
in
ancestors
:
groups
[
a
.
name
]
=
a
return
groups
.
values
()
def
get_variables
(
self
):
results
=
{}
for
group
in
self
.
groups
:
results
.
update
(
group
.
get_variables
())
results
.
update
(
self
.
vars
)
results
[
'inventory_hostname'
]
=
self
.
name
groups
=
self
.
get_groups
()
results
[
'group_names'
]
=
[
g
.
name
for
g
in
groups
if
g
.
name
!=
'all'
]
return
results
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