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
c35ef435
Commit
c35ef435
authored
Apr 18, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2716 from skvidal/first_found_skip_fix
clean up first_found to fix a few issues:
parents
5f1e2afc
7b8cec3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
35 deletions
+86
-35
lib/ansible/runner/lookup_plugins/first_found.py
+86
-35
No files found.
lib/ansible/runner/lookup_plugins/first_found.py
View file @
c35ef435
...
@@ -63,9 +63,46 @@
...
@@ -63,9 +63,46 @@
# with_first_found:
# with_first_found:
# - files: generic
# - files: generic
# paths: tasks/staging tasks/production
# paths: tasks/staging tasks/production
# this will include the tasks in the file generic where it is found first (staging or production)
# this will include the tasks in the file generic where it is found first (staging or production)
# example simple file lists
#tasks:
#- name: first found file
# action: copy src=$item dest=/etc/file.cfg
# with_first_found:
# - files: foo.${inventory_hostname} foo
# example skipping if no matched files
# First_found also offers the ability to control whether or not failing
# to find a file returns an error or not
#
#- name: first found file - or skip
# action: copy src=$item dest=/etc/file.cfg
# with_first_found:
# - files: foo.${inventory_hostname}
# skip: true
# the above will return an empty list if the files cannot be found at all
# if skip is unspecificed or if it is set to false then it will return a list
# error which can be caught bye ignore_errors: true for that action.
# finally - if you want you can use it, in place to replace first_available_file:
# you simply cannot use the - files, path or skip options. simply replace
# first_available_file with with_first_found and leave the file listing in place
#
#
# - name: with_first_found like first_available_file
# action: copy src=$item dest=/tmp/faftest
# with_first_found:
# - ../files/foo
# - ../files/bar
# - ../files/baz
# ignore_errors: true
from
ansible
import
utils
,
errors
from
ansible
import
utils
,
errors
import
os
import
os
...
@@ -79,45 +116,59 @@ class LookupModule(object):
...
@@ -79,45 +116,59 @@ class LookupModule(object):
terms
=
utils
.
listify_lookup_plugin_terms
(
terms
,
self
.
basedir
,
inject
)
terms
=
utils
.
listify_lookup_plugin_terms
(
terms
,
self
.
basedir
,
inject
)
result
=
None
result
=
None
anydict
=
False
skip
=
False
for
term
in
terms
:
for
term
in
terms
:
if
isinstance
(
term
,
dict
):
if
isinstance
(
term
,
dict
):
files
=
term
.
get
(
'files'
,
[])
anydict
=
True
paths
=
term
.
get
(
'paths'
,
[])
if
anydict
:
filelist
=
files
for
term
in
terms
:
if
isinstance
(
files
,
basestring
):
if
isinstance
(
term
,
dict
):
files
=
files
.
replace
(
','
,
' '
)
files
=
term
.
get
(
'files'
,
[])
files
=
files
.
replace
(
';'
,
' '
)
paths
=
term
.
get
(
'paths'
,
[])
filelist
=
files
.
split
(
' '
)
skip
=
utils
.
boolean
(
term
.
get
(
'skip'
,
False
))
pathlist
=
paths
filelist
=
files
if
paths
:
if
isinstance
(
files
,
basestring
):
if
isinstance
(
paths
,
basestring
):
files
=
files
.
replace
(
','
,
' '
)
paths
=
paths
.
replace
(
','
,
' '
)
files
=
files
.
replace
(
';'
,
' '
)
paths
=
paths
.
replace
(
':'
,
' '
)
filelist
=
files
.
split
(
' '
)
paths
=
paths
.
replace
(
';'
,
' '
)
pathlist
=
paths
.
split
(
' '
)
pathlist
=
paths
if
paths
:
total_search
=
[]
if
isinstance
(
paths
,
basestring
):
paths
=
paths
.
replace
(
','
,
' '
)
paths
=
paths
.
replace
(
':'
,
' '
)
if
not
pathlist
:
paths
=
paths
.
replace
(
';'
,
' '
)
total_search
=
filelist
pathlist
=
paths
.
split
(
' '
)
total_search
=
[]
if
not
pathlist
:
total_search
=
filelist
else
:
for
path
in
pathlist
:
for
fn
in
filelist
:
f
=
path
+
'/'
+
fn
total_search
.
append
(
f
)
else
:
else
:
for
path
in
pathlist
:
total_search
=
[
term
]
for
fn
in
filelist
:
else
:
f
=
path
+
'/'
+
fn
total_search
=
terms
total_search
.
append
(
f
)
else
:
total_search
=
[
term
]
result
=
None
result
=
None
for
fn
in
total_search
:
for
fn
in
total_search
:
path
=
utils
.
path_dwim
(
self
.
basedir
,
fn
)
path
=
utils
.
path_dwim
(
self
.
basedir
,
fn
)
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
return
[
path
]
return
[
path
]
if
not
result
:
if
not
result
:
raise
errors
.
AnsibleError
(
"no match found:
%
s,
%
s"
%
(
pathlist
,
filelist
))
if
skip
:
return
[]
else
:
return
[
None
]
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