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
b69ab89e
Commit
b69ab89e
authored
Oct 31, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'include_files' of
git://github.com/bennojoy/ansible
into devel
parents
187ebf2f
b53e7353
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
0 deletions
+110
-0
lib/ansible/runner/action_plugins/include_files.py
+66
-0
library/utilities/include_files
+44
-0
No files found.
lib/ansible/runner/action_plugins/include_files.py
0 → 100644
View file @
b69ab89e
# (c) 2013, Benno Joy <benno@ansibleworks.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/>.
import
os
from
ansible.utils
import
template
from
ansible
import
utils
from
ansible
import
errors
from
ansible.runner.return_data
import
ReturnData
class
ActionModule
(
object
):
NEEDS_TMPPATH
=
False
def
__init__
(
self
,
runner
):
self
.
runner
=
runner
def
run
(
self
,
conn
,
tmp
,
module_name
,
module_args
,
inject
,
complex_args
=
None
,
**
kwargs
):
if
not
module_args
and
not
'first_available_file'
in
inject
:
result
=
dict
(
failed
=
True
,
msg
=
"No Source file Given."
)
return
ReturnData
(
conn
=
conn
,
comm_ok
=
True
,
result
=
result
)
if
'first_available_file'
in
inject
:
found
=
False
for
fn
in
self
.
runner
.
module_vars
.
get
(
'first_available_file'
):
fn_orig
=
fn
fnt
=
template
.
template
(
self
.
runner
.
basedir
,
fn
,
inject
)
fnd
=
utils
.
path_dwim
(
self
.
runner
.
basedir
,
fnt
)
if
not
os
.
path
.
exists
(
fnd
)
and
'_original_file'
in
inject
:
fnd
=
utils
.
path_dwim_relative
(
inject
[
'_original_file'
],
'templates'
,
fnt
,
self
.
runner
.
basedir
,
check
=
False
)
if
os
.
path
.
exists
(
fnd
):
source
=
fnd
found
=
True
break
if
not
found
:
result
=
dict
(
failed
=
True
,
msg
=
"could not find src in first_available_file list"
)
return
ReturnData
(
conn
=
conn
,
comm_ok
=
False
,
result
=
result
)
if
not
found
:
source
=
module_args
source
=
template
.
template
(
self
.
runner
.
basedir
,
source
,
inject
)
if
'_original_file'
in
inject
:
source
=
utils
.
path_dwim_relative
(
inject
[
'_original_file'
],
'files'
,
source
,
self
.
runner
.
basedir
)
else
:
source
=
utils
.
path_dwim
(
self
.
runner
.
basedir
,
source
)
if
os
.
path
.
exists
(
source
):
data
=
utils
.
parse_yaml_from_file
(
source
)
if
type
(
data
)
!=
dict
:
raise
errors
.
AnsibleError
(
"
%
s must be stored as a dictionary/hash"
%
source
)
result
=
dict
(
ansible_facts
=
data
)
return
ReturnData
(
conn
=
conn
,
comm_ok
=
True
,
result
=
result
)
else
:
result
=
dict
(
failed
=
True
,
msg
=
"Source file not found."
,
file
=
source
)
return
ReturnData
(
conn
=
conn
,
comm_ok
=
True
,
result
=
result
)
library/utilities/include_files
0 → 100644
View file @
b69ab89e
# -*- mode: python -*-
# 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/>.
DOCUMENTATION
=
'''
---
author: Benno Joy
module: include_files
short_description: Load variables in a file from a task
description:
- This module allows loading variables from a yaml file similar to vars_files but from a task.
it would be specially useful for conditionally loading vars file from a role.
- These variables will survive between plays.
options:
free-form:
description:
- Add the file name from which variables should be loaded, if called from a role it will look for
the file in files directory else the path would be relative to playbook. An absolute path can
also be provided.
required: false
version_added: "1.4"
'''
EXAMPLES
=
'''
# Example loading variable conditionally based on os distribution
- include_files: "{{ ansible_os_distribution }}.yml"
# Example loading multiple variable files
- include_files: "{{ item }}"
with_fileglob: "*.yml"
#Example loading the first available file
- include_files:
first_available_file:
- "foo.yml"
- "bar.yml"
'''
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