Commit graph

1508 commits

Author SHA1 Message Date
Michael DeHaan
53ac0bbec2 Instantiate callback plugins only once so we can set play/task objects on them and they'll stick. 2013-04-20 09:09:35 -04:00
Dale Sedivec
c8f4a56cad Don't send unicode instances to the selinux module
This fixes #2632.  Briefly: specifying things like paths using complex
args in a playbook will make the objects unicode instances.  The selinux
module does not accept unicode instances for its char * arguments; it
wants str instances.

Per mpdehaan's comment on #2632 I just went ahead and converted all
paths to UTF-8.  I don't know if it would be better to do something like
converting to locale.getpreferredencoding(), but I factored all the
conversions out into new method _to_filesystem_str, so there's only one
place that needs to be changed in the future.
2013-04-19 20:12:11 -05:00
Michael DeHaan
df93d7dd97 Ignore inventory config files when using an inventory directory. 2013-04-19 19:01:19 -04:00
Michael DeHaan
8e7dc3c79c Remove an extra space in the module execution line if no environment was set. 2013-04-19 08:11:56 -04:00
Dag Wieers
b13beb3689 New module 'set_fact' to define host facts
This module allows you to set host facts (or export play variables to the playbook scope if you fancy that).

The module also accepts complex arguments.

```yaml
 - action: set_fact fact="something" global_fact="${local_var}"'
 - action: set_fact
   args:
      fact: something
      global_fact: ${local_var}
```
2013-04-18 23:06:58 +02:00
Seth Vidal
7b8cec3f59 clean up first_found to fix a few issues:
- add a skip option so it won't raise an exception if you don't match anything
 - make it work as a drop-in replacement for first_available_file
 - document in the module comments all of the above cases
2013-04-18 16:47:10 -04:00
Michael DeHaan
5f1e2afc34 Revert "make atomic_replace use shutil.copy2 instead of os.rename() so it will work across filesystems".
AR function was leaving some tmp files behind, want to revert, will have better implementation soon, this is the old way now.

This reverts commit f74a1fa4f0.
2013-04-18 15:46:42 -04:00
Michael DeHaan
d8bf87b008 (A) include errors in inventory scripts should they occur.
(B) allow registration with ignore_errors: True
2013-04-17 22:27:00 -04:00
Bernhard Weitzhofer
fb0a99e5d8 Fix if-statement that always evaluates True 2013-04-17 19:40:06 +02:00
C. Morgan Hamill
88eb5516eb Fix 'sequence' plugin error.
If 'terms' is a string, replace it with a single item list.
2013-04-17 11:45:28 -04:00
C. Morgan Hamill
663d37b537 Fix errors in lookup plugins.
Lookup plugins 'sequence' and 'template' now import 'ansible.utils'
appropriately in order to use the 'listify_lookup_plugin_terms'
function.

Also, 'dnstxt' and 'env' now check to see if 'terms' is a string;
without this calls like '{{ lookup('env', 'HOME') }}' fail.
2013-04-17 11:31:38 -04:00
Dale Sedivec
515fd9e915 copy action plug-in check mode respects force=no
The copy action accepts force=no, which tells it not to replace an
existing file even if it differs from the source.  The copy action
plug-in wasn't respecting this option when operated in check mode, so it
would report that changes are necessary in check mode even though copy
would make no changes when run normally.

Runner._remote_md5 was changed to make the logic for setting rc perhaps
a little more clear, and to make sure that rc=0 when the file does not
exist.
2013-04-16 20:22:51 -04:00
Michael DeHaan
7c6341718e Merge branch 'combine_vars' of git://github.com/laggyluke/ansible into exp
Conflicts:
	lib/ansible/inventory/vars_plugins/group_vars.py
	lib/ansible/runner/__init__.py
	lib/ansible/utils/__init__.py
	test/TestPlayBook.py
2013-04-16 20:06:06 -04:00
C. Morgan Hamill
863cb50530 Allow '.yml'/'.yaml' extension on group_vars files.
Look for a file with the base name of the group/host, first without
a file extension, then with a '.yml' extension, and, finally, with
a '.yaml' extension, loading vars from only the first one found.
2013-04-16 19:59:23 -04:00
Michael DeHaan
b54e955595 Remove a debug statement. 2013-04-16 19:09:12 -04:00
Michael DeHaan
86d47bce5f Make more lookup plugins tolerant of new variable system, with a little better 'do what I mean' logic to resolving
what happens if you get a string back as a template result.
2013-04-16 19:07:19 -04:00
Michael DeHaan
c0f8af5202 Make more lookup plugins happy with newstyle variables. Not quite done, but this fixes up with_items/with_nested/file/fileglob. 2013-04-16 18:50:30 -04:00
Seth Vidal
f74a1fa4f0 make atomic_replace use shutil.copy2 instead of os.rename() so it will
work across filesystems
2013-04-16 15:15:58 -04:00
Michael DeHaan
0944e7d56a Make less template calls on playbook objects. 2013-04-12 21:48:01 -04:00
Michael DeHaan
44a9352338 Also template handlers only at the end. 2013-04-12 20:32:35 -04:00
Michael DeHaan
e7f5186dec Merge pull request #2623 from willthames/when_set_bug
Prevent premature variable substitution in tasks
2013-04-12 17:19:25 -07:00
Michael DeHaan
3ab0ed5fd4 Allow 'when' and 'with_items' to be applied to roles. 2013-04-12 19:02:56 -04:00
Michael DeHaan
7a2d493e67 Teach lookup plugins that if they can't evaluate something they can wait and do it later. 2013-04-12 18:44:40 -04:00
Michael DeHaan
3f3b2a9448 Smush Jinja2 braces in playbooks so unresolved variables get parsed nicely 2013-04-12 18:38:48 -04:00
Michael DeHaan
7037023aa8 Make debug print things nicer if {{ foo }} didn't interpolate 2013-04-12 15:02:54 -04:00
Michael DeHaan
793a3d3f76 More 1.2 templating development; for legacy when_string constructs don't quote the 'in' operator 2013-04-12 13:29:49 -04:00
Michael DeHaan
85099be48f Merge pull request #2656 from dstoflet/first_available_file_fix
Quick fix for first_available_file and role support
2013-04-12 08:56:26 -07:00
Michael DeHaan
b8c5a58b7f Avoid running through the legacy template code if no dollar signs are in strings. 2013-04-12 10:33:55 -04:00
Michael DeHaan
251f19263c Remove unneeded import. 2013-04-12 10:23:53 -04:00
Michael DeHaan
8457cf433d Update pause module to not use utils.template 2013-04-12 10:00:20 -04:00
Darryl Stoflet
c63207bf75 Quick fix for first_available_file and roles 2013-04-11 20:40:23 -07:00
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
a05361f515 This is a fix on top of the 'airplane variable upgrade' commits that fixes legacy when_string so it evaluates correctly in the new eval construct. 2013-04-11 17:20:40 -04:00
Michael DeHaan
3e736eaf00 Merge pull request #2622 from skvidal/playbook-start-at-task
implement --start-at-task option to hop to a specific task before starti...
2013-04-11 11:17:24 -07:00
Michael DeHaan
4e79bd0872 Remove unneccessary construction of Jinja2 environment object. 2013-04-11 12:59:33 -04:00
Michael DeHaan
2f5c1d3788 Merge pull request #2629 from stoned/fix-jinja2-filters-init
Fix Jinja2 filter plugins initialization
2013-04-11 09:57:04 -07:00
Michael DeHaan
11a819cc4b Merge pull request #2631 from stoned/templates-filters-base64
Add base64 encode and decode filters to templates
2013-04-11 09:49:27 -07:00
Michael DeHaan
a6777f7e7c Fix template call in group_by module. 2013-04-11 12:43:02 -04:00
Michael DeHaan
7931597a6a Fix template call. 2013-04-11 12:15:13 -04:00
Michael DeHaan
695acc2de0 Make lookup plugins accessible in templates 2013-04-10 19:19:01 -04:00
Michael DeHaan
5b2035edd9 Changes for 'make pep8' 2013-04-10 19:12:10 -04:00
Michael DeHaan
81a926547c Some continued work on new-style templates and associated test code changes. Legacy template functions
are marked with "legacy_" for possible future removal.
2013-04-10 19:09:57 -04:00
Michael DeHaan
f0b21dcc0f allow references to names of variables in with_items without needing to surround them with Jinja2 '{{' delimeters 2013-04-10 18:42:54 -04:00
Michael DeHaan
9ac25bb8f6 Minor formatting 2013-04-10 18:19:31 -04:00
Michael DeHaan
d7206d84bb Allows Jinja2 that starts a YAML line to not cause a syntax error.
Technically this isn't quite valid YAML when this happens, so we make it valid.  This means that if a future commander
API allows save/load it should make sure it does similar processing.
2013-04-10 18:07:19 -04: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
804056a563 Use Jinja2 strict undefined in string templating to allow the default filter to be used. 2013-04-10 16:45:53 -04:00
Michael DeHaan
998230a84a Allow $foo and {{ bar }} to be used on the same line in playbooks. 2013-04-10 16:40:49 -04:00
Michael DeHaan
29209c4913 Style fixes so "make pep8" is clean. 2013-04-10 16:37:49 -04:00
Michael DeHaan
0113951580 Enable usage of when_set within new eval system. 2013-04-10 16:26:59 -04:00
Michael DeHaan
a83e10d77d Use safe_eval vs eval. 2013-04-10 16:17:24 -04:00
Michael DeHaan
fecfbf9226 Allow jinja2 evals that produce lists to be used in with_items. Ideally want something a bit less heavy
than the eval here.
2013-04-10 15:22:08 -04:00
Michael DeHaan
c5d9823467 Fix some items related to playbook includes and indentation. 2013-04-10 15:04:41 -04:00
Stoned Elipot
0893562605 Add base64 encode and decode filters to templates 2013-04-10 02:30:31 +02:00
Michael DeHaan
290780d13f Playbook + with_items was an undocumented feature that was causing problems because it would
evaluate and replace '$item' with ''.  Really it doesn't make sense to include multiple playbooks
via a loop variable, as you can do this with task + with_items already (and it's a simpler code
path).  Given this is undocumented, this removes that feature, and we'll consider next how to
also add 'with_items' support directly to roles.
2013-04-09 20:13:55 -04:00
Michael DeHaan
c64f19dc5f Don't set the item variable as eager template replacement will over-replace the variable as an empty string. 2013-04-09 19:57:53 -04:00
Stoned Elipot
154f58f82d Fix Jinja2 filter plugins initialization
_get_filter_plugins() checks FILTER_PLUGINS against None hence
the latter should be initialized to None.
2013-04-09 22:38:24 +02:00
Seth Vidal
690738ea32 implement --start-at-task option to hop to a specific task before starting running them 2013-04-09 01:53:40 -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
Michael DeHaan
61f2668b0a Don't include the '.yml' in the path to the retry files. 2013-04-08 12:38:05 -04:00
Michael DeHaan
0d530f3bf0 Change the retry logic to write a limit file, able to source limit from files by indicating with @filename 2013-04-08 12:36:01 -04:00
Michael DeHaan
c695aa2d6a When playbooks fail, attempt to create an inventory file in the inventory directory that allows rerunning
of the playbook against only the hosts that failed.
2013-04-07 23:37:10 -04:00
Michael DeHaan
5fef2ffb9d Merge pull request #2592 from stoned/include-task-when
when: condition support for tasks include
2013-04-06 16:01:44 -07:00
Michael DeHaan
00252353b9 Decided I liked the asterisks 2013-04-06 18:58:55 -04:00
Michael DeHaan
bc0be456da Modify output banners to have constant length and use dashes instead
of "-" to be less visually heavy (unless cowsay is installed of course)
2013-04-06 18:52:30 -04:00
Stoned Elipot
1ed54b9b3a when: condition support for tasks include 2013-04-07 00:43:39 +02:00
Michael DeHaan
e9d11173cd Remove obsolete comment 2013-04-06 18:38:31 -04: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
Sébastien Bocahu
b94bf051d5 Makes $PIPE and $FILE macros accept utf-8 input 2013-04-06 23:28:15 +02: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
Michael DeHaan
4cd69e81b9 Catch recursive templating errors and display what string caused them. 2013-04-06 09:55:31 -04:00
George Miroshnykov
6826aa7360 Tweaked merge_hash to also affect Runner behavior 2013-04-06 13:06:38 +03:00
Blair Zajac
36b3fc3acf Fix for inventory scripts with no path prefix that are in CWD.
Without this, using '-i ec2.py' will not work if '.' is not in PATH.
2013-04-05 20:52:59 -07:00
Michael DeHaan
f585c4cde7 Upgraded variable support met with upgraded conditional support, see examples/playbooks/upgraded_vars.yml
for details!
2013-04-05 19:10:32 -04:00
Michael DeHaan
38c2b14339 Undefined Jinja2 statements are returned as they originally are so you can tell there are things to
correct.
2013-04-05 17:36:53 -04:00
Michael DeHaan
49d28b9a44 This SELinux commit is too strict and we should only fail if trying to read/tweak SELinux attributes else
python-selinux can't be installed w/ the yum module when missing.

Revert "Added an extra check for target nodes with selinux but without libselinux-python package installed"

This reverts commit 550986b6a1.
2013-04-05 14:54:11 -04:00
Michael DeHaan
2c881e2b3d Merge pull request #2578 from arrfab/selinux-fix-2
Added an extra check for target nodes with selinux but without libselinux-python package installed
2013-04-05 11:52:14 -07:00
Michael DeHaan
9073aa17ab Chroot also needs args/kwargs. 2013-04-05 14:50:15 -04:00
Michael DeHaan
3d25b4a7c0 Standardize args/kwargs on connection plugins. 2013-04-05 14:50:15 -04:00
Dag Wieers
d5d26bab9b Make private key customizable per host using ansible_ssh_private_key_file configurable as variable
This fixes issue #1026 for @toshywoshy together with ansible_ssh_user and ansible_ssh_port.
2013-04-05 14:50:15 -04:00
Fabian Arrotin
550986b6a1 Added an extra check for target nodes with selinux but without libselinux-python package installed 2013-04-05 20:37:58 +02:00
Michael DeHaan
8c859f6f61 Merge pull request #2570 from skvidal/devel
simple fix for issue 2564
2013-04-05 11:07:22 -07:00
Michael DeHaan
550bf47636 Merge pull request #2565 from willthames/default_exec
Added DEFAULT_EXECUTABLE as a constant
2013-04-05 10:56:56 -07:00
Michael DeHaan
f37da4fdd7 Merge branch 'ssh_config_user_overrides' of git://github.com/bcoca/ansible into devel 2013-04-05 13:09:38 -04:00
Michael DeHaan
b67cd6bbda Merge branch 'any-errors-fatal' of git://github.com/junegunn/ansible into devel 2013-04-05 13:07:23 -04:00
Seth Vidal
2796b5ee2a simple fix for issue 2564
when we encounter a group we've not seen before - we need
to make sure we make it a subgroup of 'all', no matter what
2013-04-04 12:44:39 -04:00
willthames
e55e123c01 Added DEFAULT_EXECUTABLE as a constant
Use DEFAULT_EXECUTABLE when no executable is passed to
_low_level_command_exec

Works as a standard constant - can be overridden in all the normal ways
and defaults to /bin/sh

Motiviation is for a user that only has /bin/bash in /etc/sudoers
2013-04-04 13:32:23 +10:00
Michael DeHaan
cdaa2085ee Preliminary ability to use Jinja2 {{ }} to replace ${foo.bar} in playbooks. Can't use both at the same time per line. 2013-04-03 01:04:16 -04:00
Michael DeHaan
aa4ad80bda Update release version. 2013-04-02 20:48:30 -04:00
Junegunn Choi
b874027b36 compare the number of available hosts before and after running each task 2013-03-29 13:13:22 +09:00
Junegunn Choi
20a48c6bdf terminate immediately on a failure 2013-03-28 15:17:01 +09:00
Brian Coca
82c3b4e685 now ssh connection plugin will only pass user as an option to ssh if it is
differnt from the current user. This should enable overrides for user in
.ssh/config w/o breaking any current functionality.

Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
2013-03-27 16:41:54 -04:00
Michael DeHaan
42b0e51223 Upgrade callbacks further, now '.play', '.task', and so on are also available! 2013-03-25 22:56:32 -04:00
Michael DeHaan
0d11f53eff Let the callbacks see the playbook and (current) runner objects. 2013-03-25 22:47:06 -04:00
Michael DeHaan
783a12cc0e Resolve merge commit. 2013-03-25 22:32:01 -04:00