willthames
377bc31311
Prevent premature substitution of variables into tasks
...
As documented in #2623 , early variable substitution causes when_
tests to fail and possibly other side effects.
I can see the reason for this early substitution, likely introduced
in 1dfe60a6
, to allow many playbook parameters to be templated.
This is a valid goal, but the recursive nature of the utils.template
function means that it goes too far.
At this point removing tasks from the list of parameters to be
substituted seems sufficient to make my tests pass. It may be the
case that other parameters should be excluded, but I suspect not.
Adding a test case. I would prefer to analyse not just the aggregate
statistics but also whether the results are as expected - I can't
see an easy way to do that with the available callbacks at present.
2013-04-12 09:17:03 +10:00
Michael DeHaan
b09ef21ec9
Add code to flag legacy templating like $foo.{bar} as deprecated in favor of Jinja2 {{ foo.bar }} so we
...
can remove the legacy system at a later date.
2013-04-10 17:52:35 -04:00
Michael DeHaan
29209c4913
Style fixes so "make pep8" is clean.
2013-04-10 16:37:49 -04:00
willthames
9d87733f98
Test case and fix for shlex.split unicode bug
...
When operating on a unicode string in python 2.6, shlex.split returns
a result that does not work with the file constructor.
To reproduce this requires a task include that is templated (this is
because the templated string is a unicode result, whereas a non-
templated string is a non-unicode string)
[will@centos6.3] $ python
Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shlex
>>> shlex.split(u'abc')
['a\x00\x00\x00b\x00\x00\x00c\x00\x00\x00']
[will@fedora17] $ python
Python 2.7.3 (default, Jul 24 2012, 10:05:38)
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shlex
>>> shlex.split(u'abc')
['abc']
The proposed fix (coercing the include parameters to string before the
shlex.split) may not be ideal but it does fix the bug for my test case.
2013-04-08 14:47:43 +10:00
Stoned Elipot
1ed54b9b3a
when: condition support for tasks include
2013-04-07 00:43:39 +02:00
Michael DeHaan
fffb1a0a9d
Loose tasks not in roles get executed after roles.
2013-04-06 18:36:25 -04:00
Michael DeHaan
f044fc344b
When using roles, or other includes, the path to DWIM inside is the path of the task include
...
file.
2013-04-06 18:32:36 -04:00
Michael DeHaan
5c4ed72571
Demo of parameterized roles!
2013-04-06 12:51:17 -04:00
Michael DeHaan
f308194b9a
Added examples of how roles work!
2013-04-06 12:35:35 -04:00
Michael DeHaan
892484812e
Much requested feature -- allows relative imports of content within roles or relative to any task or handler include (../templates for template ../files for copy)
2013-04-06 12:13:04 -04:00
Michael DeHaan
95f30f0def
Complete streamlining of vars handling in playbooks and how those are templated to avoid
...
repeat template calls at playbook intialization time.
2013-04-06 10:45:09 -04:00
Michael DeHaan
1dfe60a6ea
Allow any parameter in a play to be set by --extra-vars through cleaner use of data structure
...
templating.
2013-04-06 10:09:16 -04:00
George Miroshnykov
6826aa7360
Tweaked merge_hash to also affect Runner behavior
2013-04-06 13:06:38 +03:00
Junegunn Choi
20a48c6bdf
terminate immediately on a failure
2013-03-28 15:17:01 +09:00
Michael DeHaan
783a12cc0e
Resolve merge commit.
2013-03-25 22:32:01 -04:00
milan
80dbab3cf0
check type of task explicitly
2013-03-14 13:06:55 +01:00
Michael DeHaan
9cf66f4376
Fixes from 'make pep8'. Partial, more to come.
2013-02-17 19:40:38 -05:00
Michael DeHaan
c8878998d1
update some of many copyright dates but we can just do this when editing each file, not super high priority
2013-02-16 15:32:01 -05:00
Daniel Hokka Zakrisson
57e51f7fdf
Clean up some extra_vars redundancy
2013-02-11 23:25:50 +01:00
Daniel Hokka Zakrisson
a025cfcb33
Add on_import_for_host callback from non-list case
2013-02-03 23:37:29 +01:00
Daniel Hokka Zakrisson
a79373f6b2
Make template_ds the only templater
...
Instead of having to remember when to use which one, rename template_ds
to template and move the last bit of code from template to varReplace
(which gets used for all string replacements, in the end).
This means that you can template any data type without worrying about
whether it's a string or not, and the right thing will happen.
2013-02-03 14:01:54 +01:00
Daniel Hokka Zakrisson
f7e286cf34
Fix error format for invalid vars_files
2013-01-31 20:25:28 +01:00
Seth Vidal
f649777072
- make extra-vars override all other vars and facts in playbooks
2013-01-30 11:56:04 -05:00
Michael DeHaan
0030a2bd09
Allow handler files to be empty lists.
2013-01-27 10:40:29 -05:00
Daniel Hokka Zakrisson
94a1c221bc
Update variable precedence section with current rules
2013-01-22 16:56:04 +01:00
Rodney Quillo
395093e0bf
Move default arguments to the end of the function call.
2013-01-19 08:34:47 +08:00
Rodney Quillo
7ae100611c
Adding default on vars_prompt
2013-01-18 19:00:57 +08:00
Daniel Hokka Zakrisson
caee51e90e
Allow only_if/when_* on task includes and apply it on all tasks within
2013-01-04 00:15:13 +01:00
Daniel Hokka Zakrisson
07b215d4fa
Check for non-accepted arguments combined with task includes
...
Throw an appropriate error for it.
2013-01-03 23:36:42 +01:00
Daniel Hokka Zakrisson
68f736e8d7
Make inventory variables available to vars_files
2013-01-03 23:16:38 +01:00
Daniel Hokka Zakrisson
a1877b2213
Allow infinite depth task includes
2013-01-03 23:01:04 +01:00
Nandor Sivok
f31fbdff1f
moving int() conversion to the play init
2012-12-14 18:05:08 +01:00
Nandor Sivok
e91db5fcdc
fixes #1767 parsing serial from extra_vars
2012-12-14 13:21:58 +01:00
Daniel Hokka Zakrisson
ebd31af940
Don't prompt for vars in extra-vars
...
Fixes #1622 .
2012-11-26 22:07:57 +01:00
Daniel Hokka Zakrisson
94fc3006e9
Make variables local to the play
...
Fixes #1677 .
2012-11-26 22:07:57 +01:00
Daniel Hokka Zakrisson
d1c285b70b
Port may be an integer when parsed from the play
2012-11-21 17:20:03 +01:00
Daniel Hokka Zakrisson
3ce63d845e
remote_port is None by default
2012-11-21 14:10:10 +01:00
Dag Wieers
8458f53014
Allow the remote port to be templated
...
This was requested on the mailinglist and seems useful.
2012-11-20 18:53:40 +01:00
Daniel Hokka Zakrisson
0be1f11ed5
Use all available vars for hosts:, user: and sudo_user:
2012-11-13 12:20:07 +01:00
Daniel Hokka Zakrisson
383dc30560
Rename varReplaceWithItems to template_ds
2012-11-09 15:43:29 +01:00
Daniel Hokka Zakrisson
e05e514861
Create a plugin loader system
2012-11-02 01:24:14 +01:00
Daniel Hokka Zakrisson
c519d5dac0
Add a template lookup plugin
...
Requires that inject be passed to run
2012-10-31 16:57:10 +01:00
Daniel Hokka Zakrisson
37d9acc097
Make lookup API extensible and allow basedir to be passed
...
This allows using with_fileglob in play context, e.g.
- include: $item
with_fileglob: tasks/*.yml
as well as prepares for other data to be passed.
2012-10-31 16:55:38 +01:00
Michael DeHaan
c0747b7baa
pep8 fixes
2012-10-30 20:42:07 -04:00
Daniel Hokka Zakrisson
e72fdccd87
Allow vars_files sequences without a default
2012-10-28 16:35:22 +01:00
Michael DeHaan
6ba30170dd
Make group_vars and host_vars available to usr/bin/ansible, and make vars_plugins exist
2012-10-26 19:55:59 -04:00
Daniel Hokka Zakrisson
2f05e95d8a
Use lookup plugins for task include with_*
2012-10-25 15:13:34 +02:00
Michael DeHaan
109632e3bc
Revert "Vars specified via CLI have the highest priority."
...
Reverting as this as reported allows some variables to clobber each other.
We'll work on a different fix.
This reverts commit c5469f6367
.
2012-10-21 16:42:15 -04:00
Aleksej Romanov
c5469f6367
Vars specified via CLI have the highest priority.
2012-10-16 04:34:54 +07:00
Daniel Hokka Zakrisson
b8b34b5110
Keep processing the rest of the vars_files even if one has vars
2012-10-11 23:52:01 +02:00
Daniel Hokka Zakrisson
564a212b3c
Only gather facts once per node per playbook run
...
Unless gather_facts: True is on the play
2012-10-02 15:30:19 +02:00
Daniel Hokka Zakrisson
48c5d696d2
Remove debug print statement
2012-10-01 17:23:21 +02:00
Daniel Hokka Zakrisson
a83aa1071b
Give each task its own module_vars
...
Otherwise each task will overwrite the previous' items, among
other things.
2012-10-01 17:17:39 +02:00
Michael DeHaan
d0eba79760
Template out sudo_user so you can pass in variables using --extra-vars
2012-09-30 20:11:51 -04:00
Daniel Hokka Zakrisson
8a8ffa2342
Allow task includes to work with with_items
2012-09-30 13:40:52 +02:00
Dag Wieers
e7af005408
Revert only_if for variables and templating prompt
...
Since the condition was not templated, it wasn't working.
Only variables in local scope were used, which made this not very practical
2012-09-28 01:32:09 +02:00
Dag Wieers
6b6e3c64c8
Fix a typo in the prompt code
...
This is unfortunately related to not being able to reuse the same code that was tested.
2012-09-25 11:51:33 +02:00
Michael DeHaan
734db4ffe9
Merge pull request #1080 from dagwieers/prompt-only_if
...
Add an only_if option to vars_prompt to make prompts conditional
2012-09-24 17:42:17 -07:00
Dag Wieers
4e9a970616
Add an only_if option to vars_prompt to make prompts conditional
...
Sometimes you may want to allow variables through host_vars or inventory, but prompt for a value if it is not set or if the value does not conform to something specific. This option allows you to specify when you want to offer a prompt.
This patch also moves check_conditional to utils, and adds an is_unset() function which is nicer to read:
only_if: "not is_set('${var}')"
vs
only_if: "is_unset('${var}')"
2012-09-24 23:55:54 +02:00
Dag Wieers
069feb5d9c
Template the variable prompt to customize the message
...
We have a password-prompt for a configurable login name. Since we require to ask the password for this specific login, it is important to indicate what password needs to be prov ided on the prompt. So the prompt needs to be templated. That's what this patch does.
2012-09-24 22:37:51 +02:00
Daniel Hokka Zakrisson
cc948f339c
Allow including files through variables
...
$FILE{file} will be replaced with the contents of "file"
$PIPE{cat file} will be replaced with the output of "cat file"
2012-09-19 17:57:17 +02:00
Michael DeHaan
b8c4bb9e6e
Revert "Allow including files through variables"
...
This reverts commit bf47bb4753
.
Conflicts:
lib/ansible/utils.py
test/TestUtils.py
2012-09-19 10:31:23 -04:00
Daniel Hokka Zakrisson
bf47bb4753
Allow including files through variables
...
$FILE{file} will be replaced with the contents of "file"
$PIPE{cat file} will be replaced with the output of "cat file"
2012-09-17 16:03:59 +02:00
Lorin Hochstein
b9e100a506
Support import of playbooks in other directories
...
Previously, importing a playbook in a different directory didn't
work because all of the relative paths were resolved relative to
the top-level playbook.
This patch resolves relative paths on a per-play level instead of
relative to the directory of the top-level playbook.
Also removes the dirname argument from the Play._get_vars method
since this argument wasn't used in the metho dbody.
2012-09-09 22:59:56 -04:00
Mark Theunissen
2755602dcb
Check to make sure that tags passed as parameters actually exist
2012-08-27 21:27:07 -04:00
Michael DeHaan
2833f48ed3
Make a particular error about an invalid include statement a bit clearer.
2012-08-21 22:08:08 -04:00
Michael DeHaan
898d7676f7
Adds the 'serial' keyword to a playbook which controls how many hosts can be running through a playbook at a single time.
...
The default is 0, which means all hosts. If set to 1, each host would run a playbook all the way through before moving
on the next host. Fact gathering is still parallel, regardless of the serial setting.
2012-08-18 09:52:13 -04:00
Michael DeHaan
de221e6b4b
Add vars to host_vars to prevent some suprises
2012-08-14 20:35:01 -04:00
Michael DeHaan
6de8c27085
Load parent groups when processing group_vars
2012-08-14 19:48:33 -04:00
Michael DeHaan
72faf8eb0a
fix indents
2012-08-11 12:20:16 -04:00
Michael DeHaan
05d6e74cce
Merge branch 'vars_prompt_encrypt' of https://github.com/cocoy/ansible into devel
2012-08-09 21:41:12 -04:00
Michael DeHaan
07f459f3b2
Allow user to be passed in via --extra-vars
2012-08-09 21:14:30 -04:00
Michael DeHaan
98a5565106
Fixing up parameterized task includes such that variables can be easily handed to them.
2012-08-09 21:09:12 -04:00
Rodney Quillo
d1f821361d
vars_prompt encrypt from mgw
2012-08-09 22:56:40 +08:00
Michael DeHaan
faed4b5a33
whitespace + remove deprecated YAML parser (migration script lives in examples/scripts and warning was added
...
in 0.6 release)
2012-08-06 20:07:02 -04:00
Michael DeHaan
86ec639176
add error handling if you try to load files in the wrong data format
2012-08-01 19:51:52 -04:00
Michael DeHaan
08c5fe875b
yell if input data for host or group vars are not hashes
2012-08-01 19:46:33 -04:00
Michael DeHaan
ee5f12cd40
Slight tweaks on vars_prompt upgrades
2012-07-27 19:00:48 -04:00
Petros Moisiadis
c717934b7e
Improved 'vars_prompt' syntax to support prompt text and (non-)private input
...
An example of the new syntax:
vars_prompt:
- name: 'secret_variable_name"
prompt: "Enter secret value: "
private: "yes"
- name: "nonsecret_variable_name"
prompt: "Enter non-secret value: "
private: "no"
2012-07-27 19:00:48 -04:00
Michael DeHaan
da4562f495
changes to not clear the setup cache between runs, and also decide to run plays with no tasks
...
in them if it looks like they are not tagged, because if that is the case, then we may just
be gathering facts about them.
2012-07-25 20:45:51 -04:00
Michael DeHaan
617f9dc942
Added some caching logic to improve external inventory scripts, removed some debug statements.
2012-07-22 11:53:19 -04:00
Michael DeHaan
396b81b647
Remove this check as it wasn't really needed and in recent refinements keeps the group_vars stuff from working
...
as desired.
2012-07-22 10:06:10 -04:00
Michael DeHaan
b574c70006
host and group vars should update the setup cache
2012-07-20 10:00:51 -04:00
Michael DeHaan
ba3466af95
The following paths are now implict and optional in vars_files:
...
./group_vars/groupname.yml (for all groups the host is in)
./host_vars/hostname.yml (for the hostname given in the inventory)
This requires an actual inventory file, not script and the paths are relative
to the directory of the inventory file.
2012-07-20 09:43:45 -04:00
Peter Sankauskas
4b66d98332
Adding missing colon... can't believe I missed that... sorry
2012-07-18 17:48:13 -07:00
Peter Sankauskas
413fb15e0a
Conditional Imports should only import the first file in the list, not all of them. This change stops looping through the vars_files list as soon as a file is found.
2012-07-18 15:31:04 -07:00
Michael DeHaan
3c2cbae68e
Plays and tasks now yell when they see parameters they do not understand, so that typos like 'var' for 'vars'
...
don't result in people having to ask questions about what is wrong with their playbook
2012-07-17 19:09:36 -04:00
Michael DeHaan
e4a546e8bb
Make it possible to use variables from 'vars' in the paths to task level include statements.
2012-07-17 18:57:02 -04:00
Michael DeHaan
5f69c557b9
Fix for the way host variables were being swallowed, plus some overall simplification. Deciding what
...
dictionary to use for templating now happens in exactly one place (executor_internal) and the "inject"
dictionary is passed to what needs it.
2012-07-15 14:19:11 -04:00
Michael DeHaan
61d8e2e7c7
with_items should be processed inside the task class, also make first_available_file
...
and with_items incompatible. Most cases that would need this could be solved
with vars_files.
2012-07-15 09:17:04 -04:00
Michael DeHaan
706cfd9ade
Misc cleanup -- moved function out of utils, removed debug statement.
2012-07-15 08:50:23 -04:00
Michael DeHaan
60d64251f8
Allow gather_facts: False in a playbook as a way of disabling the fact step if you know
...
you aren't going to need it.
2012-07-14 19:49:42 -04:00
Michael DeHaan
64c51ade1e
Change the way we do with_items to make them happen next to each other in runner, which eliminates the problem of with_items and vars_files sometimes not playing nice with each other.
...
(Also a fix for the user module error handling when the user
is not present at the time of the return. This can only really be caused by multiple ansible executions).
2012-07-14 19:18:33 -04:00
Michael DeHaan
028f216689
Error handling and magic around with_items, to let you know when variables are usable inside it and when not.
2012-07-14 13:23:14 -04:00
Michael DeHaan
102b22be1f
Make the logic behind vars_files smarter, so host specific vars go into the setup cache, but other variables
...
are usable top level. This allows vars_files data to be used, most of the time, just fine in with_items,
(error handling pending) but is mostly a memory and efficiency thing.
2012-07-14 13:12:19 -04:00
Michael DeHaan
15b2b3a020
Warn if something loaded by vars_files is not a dictionary
2012-07-14 12:39:06 -04:00
Michael DeHaan
611e5b0c90
Make adding tags to a playbook work as shorthand to tagging all tasks in the play.
2012-07-12 00:58:48 -04:00
Michael DeHaan
a765deccce
Allow top level playbook files to import other playbook files, added some basic
...
playbook structure checking.
2012-07-12 00:19:44 -04:00
Michael DeHaan
969c3feb13
Allow include statements from plays to specify tags (see tags.yml example file).
...
Also be smart and don't run a play at all if no tasks in the play match any of the tags specified. This includes not running the setup actions!
2012-07-11 20:33:46 -04:00
Michael DeHaan
83f23ef861
Basic support for tagging tasks and selecting a subset of tasks to run with --tags.
2012-07-11 19:51:26 -04:00
Daniel Hokka Zakrisson
a05da2d312
Allow with_items to specify a variable
2012-06-09 21:59:22 +02:00
Daniel Hokka Zakrisson
933b5e8631
Reduce code duplication
2012-06-09 21:50:46 +02:00
Daniel Hokka Zakrisson
dff8d7be04
Expand vars_files identically for lists and non-lists
2012-06-08 01:32:56 +02:00
John Kleint
70837469c6
Properly template list of hosts in playbooks.
...
In playbooks, hosts can be a YAML list. We templated the list before
converting it to a semicolon-separated string, which actually templated its
repr. This converts to a string first. A basic unit test is included.
2012-05-31 16:06:21 -04:00
Brad Olson
7ea4a0e895
Avoid traceback when vars file has no vars items. Could warn or fail instead.
2012-05-29 10:23:09 -04:00
Cosmin Luță
74bfd7eb81
Removed line that caused stacktrace
2012-05-27 14:15:30 +03:00
Michael DeHaan
4664e354c3
Get with_items to work with new play/task architecture.
2012-05-26 01:49:23 -04:00
Michael DeHaan
ecb944892d
Tweaks on previous refactoring of playbook, version bump a 0.4 reference, remove some debug, etc
2012-05-26 01:20:53 -04:00
Michael DeHaan
b9b53d1941
Playbook refactoring -- work in progress.
2012-05-26 00:37:34 -04:00