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
21f8c0bc
Commit
21f8c0bc
authored
May 07, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'cchurch-devel' into devel
parents
b71a451e
c584b6b5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
2 deletions
+133
-2
lib/ansible/runner/action_plugins/group_by.py
+12
-1
test/integration/Makefile
+4
-1
test/integration/inventory.group_by
+6
-0
test/integration/test_group_by.yml
+111
-0
No files found.
lib/ansible/runner/action_plugins/group_by.py
View file @
21f8c0bc
...
@@ -38,6 +38,8 @@ class ActionModule(object):
...
@@ -38,6 +38,8 @@ class ActionModule(object):
# the group_by module does not need to pay attention to check mode.
# the group_by module does not need to pay attention to check mode.
# it always runs.
# it always runs.
# module_args and complex_args have already been templated for the first host.
# Use them here only to check that a key argument is provided.
args
=
{}
args
=
{}
if
complex_args
:
if
complex_args
:
args
.
update
(
complex_args
)
args
.
update
(
complex_args
)
...
@@ -68,7 +70,16 @@ class ActionModule(object):
...
@@ -68,7 +70,16 @@ class ActionModule(object):
break
break
if
next_host
:
if
next_host
:
continue
continue
group_name
=
template
.
template
(
self
.
runner
.
basedir
,
args
[
'key'
],
data
)
# Template original module_args and complex_args from runner for each host.
host_module_args
=
template
.
template
(
self
.
runner
.
basedir
,
self
.
runner
.
module_args
,
data
)
host_complex_args
=
template
.
template
(
self
.
runner
.
basedir
,
self
.
runner
.
complex_args
,
data
)
host_args
=
{}
if
host_complex_args
:
host_args
.
update
(
host_complex_args
)
host_args
.
update
(
parse_kv
(
host_module_args
))
group_name
=
host_args
[
'key'
]
group_name
=
group_name
.
replace
(
' '
,
'-'
)
group_name
=
group_name
.
replace
(
' '
,
'-'
)
if
group_name
not
in
groups
:
if
group_name
not
in
groups
:
groups
[
group_name
]
=
[]
groups
[
group_name
]
=
[]
...
...
test/integration/Makefile
View file @
21f8c0bc
...
@@ -14,7 +14,7 @@ else
...
@@ -14,7 +14,7 @@ else
CREDENTIALS_ARG
=
CREDENTIALS_ARG
=
endif
endif
all
:
non_destructive destructive check_mode test_hash test_handlers
all
:
non_destructive destructive check_mode test_hash test_handlers
test_group_by
non_destructive
:
non_destructive
:
ansible-playbook non_destructive.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
$(TEST_FLAGS)
ansible-playbook non_destructive.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
$(TEST_FLAGS)
...
@@ -25,6 +25,9 @@ destructive:
...
@@ -25,6 +25,9 @@ destructive:
check_mode
:
check_mode
:
ansible-playbook check_mode.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
--check
$(TEST_FLAGS)
ansible-playbook check_mode.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
--check
$(TEST_FLAGS)
test_group_by
:
ansible-playbook test_group_by.yml
-i
inventory.group_by
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
$(TEST_FLAGS)
test_handlers
:
test_handlers
:
ansible-playbook test_handlers.yml
-i
inventory.handlers
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
$(TEST_FLAGS)
ansible-playbook test_handlers.yml
-i
inventory.handlers
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
$(TEST_FLAGS)
...
...
test/integration/inventory.group_by
0 → 100644
View file @
21f8c0bc
[lamini]
alpaca genus=vicugna
llama genus=lama
[lamini:vars]
ansible_connection=local
test/integration/test_group_by.yml
0 → 100644
View file @
21f8c0bc
# test code for the group_by module
# (c) 2014, Chris Church <cchurch@ansible.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/>.
-
hosts
:
lamini
gather_facts
:
false
tasks
:
-
name
:
group by genus
group_by
:
key={{ genus }}
-
name
:
group by first three letters of genus with key in quotes
group_by
:
key="{{ genus | truncate(3,
true
, '') }}"
-
name
:
group by first two letters of genus with key not in quotes
group_by
:
key={{ genus | truncate(2,
true
, '') }}
-
name
:
group by genus in uppercase using complex args
group_by
:
{
key
:
"
{{
genus
|
upper()
}}"
}
-
hosts
:
vicugna
gather_facts
:
false
tasks
:
-
name
:
verify that only the alpaca is in this group
assert
:
{
that
:
"
inventory_hostname
==
'alpaca'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_vicugna=true
-
hosts
:
lama
gather_facts
:
false
tasks
:
-
name
:
verify that only the llama is in this group
assert
:
{
that
:
"
inventory_hostname
==
'llama'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_lama=true
-
hosts
:
vic
gather_facts
:
false
tasks
:
-
name
:
verify that only the alpaca is in this group
assert
:
{
that
:
"
inventory_hostname
==
'alpaca'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_vic=true
-
hosts
:
lam
gather_facts
:
false
tasks
:
-
name
:
verify that only the llama is in this group
assert
:
{
that
:
"
inventory_hostname
==
'llama'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_lam=true
-
hosts
:
vi
gather_facts
:
false
tasks
:
-
name
:
verify that only the alpaca is in this group
assert
:
{
that
:
"
inventory_hostname
==
'alpaca'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_vi=true
-
hosts
:
la
gather_facts
:
false
tasks
:
-
name
:
verify that only the llama is in this group
assert
:
{
that
:
"
inventory_hostname
==
'llama'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_la=true
-
hosts
:
VICUGNA
gather_facts
:
false
tasks
:
-
name
:
verify that only the alpaca is in this group
assert
:
{
that
:
"
inventory_hostname
==
'alpaca'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_VICUGNA=true
-
hosts
:
LAMA
gather_facts
:
false
tasks
:
-
name
:
verify that only the llama is in this group
assert
:
{
that
:
"
inventory_hostname
==
'llama'"
}
-
name
:
set a fact to check that we ran this play
set_fact
:
genus_LAMA=true
-
hosts
:
'
{{genus'
gather_facts
:
false
tasks
:
-
name
:
no hosts should match this group
fail
:
msg="should never get here"
-
hosts
:
alpaca
gather_facts
:
false
tasks
:
-
name
:
check that alpaca matched all four groups
assert
:
{
that
:
[
"
genus_vicugna"
,
"
genus_vic"
,
"
genus_vi"
,
"
genus_VICUGNA"
]
}
-
hosts
:
llama
gather_facts
:
false
tasks
:
-
name
:
check that llama matched all four groups
assert
:
{
that
:
[
"
genus_lama"
,
"
genus_lam"
,
"
genus_la"
,
"
genus_LAMA"
]
}
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