Compare commits

...

21 Commits

Author SHA1 Message Date
6f568bd649 Version bump for release 1.8.2 2014-12-04 17:08:36 -06:00
1545c73d27 Make test for skipping agree with the way current output formats a skip 2014-12-04 16:10:34 -06:00
bff88271ee fixed integration test as with_items always returns a list, even if
empty
2014-12-04 16:09:58 -06:00
b9f1503870 Merge pull request #9715 from bcoca/listify_revert_errorhandling
Listify revert errorhandling
2014-12-04 16:09:28 -06:00
ecdeed4342 changed plugin load priority to be path based, not suffix based. 2014-12-04 16:07:32 -06:00
e81a6da49b Fix checksum code to work with delegate_to/local_action
Fixes #9704
2014-12-04 16:02:54 -06:00
0a52913dfa Have remote_expanduser honor sudo and su users.
Fixes #9663
2014-12-04 16:00:04 -06:00
1393272632 Use more variable sources when templating the play ds
Fixes #9699
2014-12-04 15:59:14 -06:00
4cd87ec93e Revise patch from earlier using even more variable sources for HostVars
Superceeds e61e8a3

Fixes #9684
2014-12-04 15:59:09 -06:00
8dd3d84250 Fix PowerShell plugin issues affecting fetch module when used against Windows hosts. 2014-12-04 15:59:04 -06:00
e728ff97d9 Use additional vars when templating included file names
Fixes #9669
2014-12-04 15:59:00 -06:00
2f1e78ffee Use extra vars when creating HostVars
Fixes #9667
2014-12-04 15:58:55 -06:00
38e2757c85 Need to include extras in setup to accomodate future windows extras modules 2014-12-04 15:58:51 -06:00
d68add651e Make sure Windows modules are installed. 2014-12-04 15:58:46 -06:00
ad675235e2 Keep git history out of submodules when building src distribution 2014-11-27 20:08:48 -05:00
6598c83b02 Version bump for release 1.8.1 2014-11-26 21:42:25 -06:00
5b3c82f4ba fine tuned lookup/templating errors 2014-11-26 21:35:26 -06:00
e5344a7167 Integration tests for #9242 and #9640 2014-11-26 21:15:59 -06:00
7fcfc7450d Don't template play vars by themselves, it's too early 2014-11-26 21:15:43 -06:00
dece0c3f08 Version bump for 1.8.0 2014-11-25 15:58:28 -06:00
672a2cc037 Locking submodule SHAs for 1.8.0 2014-11-25 15:51:42 -06:00
28 changed files with 199 additions and 60 deletions

View File

@ -1,7 +1,20 @@
Ansible Changes By Release
==========================
## 1.8 "You Really Got Me" - Active Development
## 1.8.2 "You Really Got Me" - Dec 04, 2014
* Various bug fixes for packaging issues related to modules.
* Various bug fixes for lookup plugins.
* Various bug fixes for some modules (continued cleanup of postgresql issues, etc.).
## 1.8.1 "You Really Got Me" - Nov 26, 2014
* Various bug fixes in postgresql and mysql modules.
* Fixed a bug related to lookup plugins used within roles not finding files based on the relative paths to the roles files/ directory.
* Fixed a bug related to vars specified in plays being templated too early, resulting in incorrect variable interpolation.
* Fixed a bug related to git submodules in bare repos.
## 1.8 "You Really Got Me" - Nov 25, 2014
Major changes:

View File

@ -7,3 +7,5 @@ recursive-include docs *
include Makefile
include VERSION
include MANIFEST.in
prune lib/ansible/modules/core/.git
prune lib/ansible/modules/extras/.git

View File

@ -4,11 +4,14 @@ Ansible Releases at a Glance
Active Development
++++++++++++++++++
1.8 "You Really Got Me" ---- FALL 2014
1.9 "Dancing In the Streets" WINTER 2015
Released
++++++++
1.8.2 "You Really Got Me" ---- 12-04-2014
1.8.1 "You Really Got Me" ---- 11-26-2014
1.8 "You Really Got Me" ---- 11-25-2014
1.7.2 "Summer Nights" -------- 09-24-2014
1.7.1 "Summer Nights" -------- 08-14-2014
1.7 "Summer Nights" -------- 08-06-2014

View File

@ -1 +1 @@
1.8
1.8.2

View File

@ -14,5 +14,5 @@
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
__version__ = '1.8'
__version__ = '1.8.2'
__author__ = 'Michael DeHaan'

View File

@ -88,13 +88,6 @@ class Play(object):
if self.playbook.inventory.src() is not None:
load_vars['inventory_file'] = self.playbook.inventory.src()
# template the play vars with themselves and the extra vars
# from the playbook, to make sure they're correct
all_vars = utils.combine_vars(self.vars, self.playbook.extra_vars)
all_vars = utils.combine_vars(all_vars, load_vars)
self.vars = template(basedir, self.vars, all_vars)
self.vars = utils.combine_vars(self.vars, load_vars)
# We first load the vars files from the datastructure
# so we have the default variables to pass into the roles
self.vars_files = ds.get('vars_files', [])
@ -115,10 +108,16 @@ class Play(object):
self._update_vars_files_for_host(None)
# template everything to be efficient, but do not pre-mature template
# tasks/handlers as they may have inventory scope overrides
# tasks/handlers as they may have inventory scope overrides. We also
# create a set of temporary variables for templating, so we don't
# trample on the existing vars structures
_tasks = ds.pop('tasks', [])
_handlers = ds.pop('handlers', [])
ds = template(basedir, ds, self.vars)
temp_vars = utils.merge_hash(self.vars, self.vars_file_vars)
temp_vars = utils.merge_hash(temp_vars, self.playbook.extra_vars)
ds = template(basedir, ds, temp_vars)
ds['tasks'] = _tasks
ds['handlers'] = _handlers
@ -626,8 +625,14 @@ class Play(object):
dirname = self.basedir
if original_file:
dirname = os.path.dirname(original_file)
include_file = template(dirname, tokens[0], mv)
# temp vars are used here to avoid trampling on the existing vars structures
temp_vars = utils.merge_hash(self.vars, self.vars_file_vars)
temp_vars = utils.merge_hash(temp_vars, mv)
temp_vars = utils.merge_hash(temp_vars, self.playbook.extra_vars)
include_file = template(dirname, tokens[0], temp_vars)
include_filename = utils.path_dwim(dirname, include_file)
data = utils.parse_yaml_from_file(include_filename, vault_password=self.vault_password)
if 'role_name' in x and data is not None:
for y in data:

View File

@ -667,8 +667,22 @@ class Runner(object):
def _executor_internal(self, host, new_stdin):
''' executes any module one or more times '''
# We build the proper injected dictionary for all future
# templating operations in this run
inject = self.get_inject_vars(host)
hostvars = HostVars(inject['combined_cache'], self.inventory, vault_password=self.vault_pass)
# Then we selectively merge some variable dictionaries down to a
# single dictionary, used to template the HostVars for this host
temp_vars = self.inventory.get_variables(host, vault_password=self.vault_pass)
temp_vars = utils.merge_hash(temp_vars, inject['combined_cache'])
temp_vars = utils.merge_hash(temp_vars, self.play_vars)
temp_vars = utils.merge_hash(temp_vars, self.play_file_vars)
temp_vars = utils.merge_hash(temp_vars, self.extra_vars)
hostvars = HostVars(temp_vars, self.inventory, vault_password=self.vault_pass)
# and we save the HostVars in the injected dictionary so they
# may be referenced from playbooks/templates
inject['hostvars'] = hostvars
host_connection = inject.get('ansible_connection', self.transport)
@ -719,6 +733,10 @@ class Runner(object):
result = utils.jsonify(dict(changed=False, skipped=True))
self.callbacks.on_skipped(host, None)
return ReturnData(host=host, result=result)
except errors.AnsibleError, e:
raise
except Exception, e:
raise errors.AnsibleError("Unexpected error while executing task: %s" % str(e))
# strip out any jinja2 template syntax within
# the data returned by the lookup plugin
@ -1182,8 +1200,16 @@ class Runner(object):
''' takes a remote path and performs tilde expansion on the remote host '''
if not path.startswith('~'):
return path
split_path = path.split(os.path.sep, 1)
cmd = conn.shell.expand_user(split_path[0])
expand_path = split_path[0]
if expand_path == '~':
if self.sudo and self.sudo_user:
expand_path = '~%s' % self.sudo_user
elif self.su and self.su_user:
expand_path = '~%s' % self.su_user
cmd = conn.shell.expand_user(expand_path)
data = self._low_level_exec_command(conn, cmd, tmp, sudoable=False, su=False)
initial_fragment = utils.last_non_blank_line(data['stdout'])
@ -1193,7 +1219,7 @@ class Runner(object):
return path
if len(split_path) > 1:
return os.path.join(initial_fragment, *split_path[1:])
return conn.shell.join_path(initial_fragment, *split_path[1:])
else:
return initial_fragment
@ -1201,7 +1227,10 @@ class Runner(object):
def _remote_checksum(self, conn, tmp, path, inject):
''' takes a remote checksum and returns 1 if no file '''
python_interp = inject['hostvars'][inject['inventory_hostname']].get('ansible_python_interpreter', 'python')
if 'delegate_to' in inject and inject['delegate_to']:
python_interp = inject['hostvars'][inject['delegate_to']].get('ansible_python_interpreter', 'python')
else:
python_interp = inject['hostvars'][inject['inventory_hostname']].get('ansible_python_interpreter', 'python')
cmd = conn.shell.checksum(path, python_interp)
data = self._low_level_exec_command(conn, cmd, tmp, sudoable=True)
data2 = utils.last_non_blank_line(data['stdout'])

View File

@ -193,7 +193,7 @@ class Connection(object):
def fetch_file(self, in_path, out_path):
out_path = out_path.replace('\\', '/')
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
buffer_size = 2**20 # 1MB chunks
buffer_size = 2**19 # 0.5MB chunks
if not os.path.exists(os.path.dirname(out_path)):
os.makedirs(os.path.dirname(out_path))
out_file = None

View File

@ -50,7 +50,7 @@ class LookupModule(object):
if isinstance(term, basestring):
# convert a variable to a list
term2 = utils.listify_lookup_plugin_terms(term, self.basedir, inject, fail_on_undefined=False)
term2 = utils.listify_lookup_plugin_terms(term, self.basedir, inject)
# but avoid converting a plain string to a list of one string
if term2 != [ term ]:
term = term2
@ -59,7 +59,7 @@ class LookupModule(object):
# if it's a list, check recursively for items that are a list
term = self.flatten(term, inject)
ret.extend(term)
else:
else:
ret.append(term)
return ret

View File

@ -84,12 +84,24 @@ class ShellModule(object):
# FIXME: Support system temp path!
return _encode_script('''(New-Item -Type Directory -Path $env:temp -Name "%s").FullName | Write-Host -Separator '';''' % basefile)
def md5(self, path):
def expand_user(self, user_home_path):
# PowerShell only supports "~" (not "~username"). Resolve-Path ~ does
# not seem to work remotely, though by default we are always starting
# in the user's home directory.
if user_home_path == '~':
script = 'Write-Host (Get-Location).Path'
elif user_home_path.startswith('~\\'):
script = 'Write-Host ((Get-Location).Path + "%s")' % _escape(user_home_path[1:])
else:
script = 'Write-Host "%s"' % _escape(user_home_path)
return _encode_script(script)
def checksum(self, path, python_interp):
path = _escape(path)
script = '''
If (Test-Path -PathType Leaf "%(path)s")
{
$sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
$sp = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider;
$fp = [System.IO.File]::Open("%(path)s", [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
[System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
$fp.Dispose();

View File

@ -48,7 +48,6 @@ import sys
import json
import subprocess
import contextlib
import jinja2.exceptions
from vault import VaultLib
@ -1451,7 +1450,7 @@ def safe_eval(expr, locals={}, include_exceptions=False):
return expr
def listify_lookup_plugin_terms(terms, basedir, inject, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR):
def listify_lookup_plugin_terms(terms, basedir, inject):
from ansible.utils import template
@ -1469,13 +1468,11 @@ def listify_lookup_plugin_terms(terms, basedir, inject, fail_on_undefined=C.DEFA
# if not already a list, get ready to evaluate with Jinja2
# not sure why the "/" is in above code :)
try:
new_terms = template.template(basedir, "{{%s}}" % terms, inject, convert_bare=True, fail_on_undefined=fail_on_undefined)
new_terms = template.template(basedir, "{{ %s }}" % terms, inject)
if isinstance(new_terms, basestring) and "{{" in new_terms:
pass
else:
terms = new_terms
except jinja2.exceptions.UndefinedError, e:
raise errors.AnsibleUndefinedVariable('undefined variable in items: %s' % e)
except:
pass

View File

@ -167,17 +167,20 @@ class PluginLoader(object):
else:
suffixes = ['.py', '']
for suffix in suffixes:
full_name = '%s%s' % (name, suffix)
if full_name in self._plugin_path_cache:
return self._plugin_path_cache[full_name]
# loop over paths and then loop over suffixes to find plugin
for i in self._get_paths():
for suffix in suffixes:
full_name = '%s%s' % (name, suffix)
if full_name in self._plugin_path_cache:
return self._plugin_path_cache[full_name]
for i in self._get_paths():
path = os.path.join(i, full_name)
if os.path.isfile(path):
self._plugin_path_cache[full_name] = path
return path
# if nothing is found, try finding alias/deprecated
if not name.startswith('_'):
return self.find_plugin('_' + name, suffixes, transport)

View File

@ -86,14 +86,15 @@ JINJA2_ALLOWED_OVERRIDES = ['trim_blocks', 'lstrip_blocks', 'newline_sequence',
def lookup(name, *args, **kwargs):
from ansible import utils
instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None))
vars = kwargs.get('vars', None)
tvars = kwargs.get('vars', None)
if instance is not None:
# safely catch run failures per #5059
try:
ran = instance.run(*args, inject=vars, **kwargs)
ran = instance.run(*args, inject=tvars, **kwargs)
except errors.AnsibleError:
raise
except Exception, e:
ran = None
raise errors.AnsibleError('Unexpected error in during lookup: %s' % e)
if ran:
ran = ",".join(ran)
return ran

View File

@ -1,8 +1,20 @@
ansible (1.8) unstable; urgency=low
ansible (1.8.2) unstable; urgency=low
* 1.8 release (PENDING)
* 1.8.2
-- Michael DeHaan <michael@ansible.com> Wed, 21 Oct 2015 04:29:00 -0500
-- Michael DeHaan <michael@ansible.com> Thu, 04 Dec 2014 17:00:00 -0500
ansible (1.8.1) unstable; urgency=low
* 1.8.1
-- Michael DeHaan <michael@ansible.com> Wed, 26 Nov 2014 23:00:00 -0500
ansible (1.8.0) unstable; urgency=low
* 1.8.0
-- Michael DeHaan <michael@ansible.com> Tue, 25 Nov 2014 17:00:00 -0500
ansible (1.7.2) unstable; urgency=low

View File

@ -110,6 +110,15 @@ rm -rf %{buildroot}
%changelog
* Thu Dec 04 2014 Michael DeHaan <michael@ansible.com> - 1.8.2
- Release 1.8.2
* Wed Nov 26 2014 Michael DeHaan <michael@ansible.com> - 1.8.1
- Release 1.8.1
* Tue Nov 25 2014 Michael DeHaan <michael@ansible.com> - 1.8.0
- Release 1.8.0
* Wed Sep 24 2014 Michael DeHaan <michael@ansible.com> - 1.7.2
- Release 1.7.2

View File

@ -24,7 +24,7 @@ setup(name='ansible',
package_dir={ 'ansible': 'lib/ansible' },
packages=find_packages('lib'),
package_data={
'': ['module_utils/*.ps1'],
'': ['module_utils/*.ps1', 'modules/core/windows/*.ps1', 'modules/extras/windows/*.ps1'],
},
scripts=[
'bin/ansible',

View File

@ -57,7 +57,7 @@ test_hash:
ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook test_hash.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}'
test_var_precedence:
ansible-playbook test_var_precedence.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e 'extra_var=extra_var'
ansible-playbook test_var_precedence.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e 'extra_var=extra_var' -e 'extra_var_override=extra_var_override'
test_vault:
ansible-playbook test_vault.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) --vault-password-file $(VAULT_PASSWORD_FILE) --list-tasks

View File

@ -1,6 +1,8 @@
- hosts: testhost
gather_facts: True
roles:
# In destructive because it creates and removes a user
- { role: test_sudo, tags: test_sudo}
- { role: test_service, tags: test_service }
# Current pip unconditionally uses md5. We can re-enable if pip switches
# to a different hash or allows us to not check md5

View File

@ -9,6 +9,10 @@ testhost2 ansible_ssh_host=127.0.0.1 ansible_connection=local
[inven_overridehosts]
invenoverride ansible_ssh_host=127.0.0.1 ansible_connection=local
[all:vars]
extra_var_override=FROM_INVENTORY
inven_var=inventory_var
[inven_overridehosts:vars]
foo=foo
var_dir=vars

View File

@ -276,8 +276,9 @@
- name: assert the task was skipped
assert:
that:
- "'skipped' in result"
- result.skipped
- "result.results|length == 1"
- "'skipped' in result.results[0]"
- "result.results[0].skipped == True"
- name: test a with_items loop skipping a single item
debug: var=item

View File

@ -0,0 +1,44 @@
- include_vars: default.yml
- name: Create test user
user:
name: "{{ sudo_test_user }}"
- name: tilde expansion honors sudo in file
sudo: True
sudo_user: "{{ sudo_test_user }}"
file:
path: "~/foo.txt"
state: touch
- name: check that the path in the user's home dir was created
stat:
path: "~{{ sudo_test_user }}/foo.txt"
register: results
- assert:
that:
- "results.stat.exists == True"
- name: tilde expansion honors sudo in template
sudo: True
sudo_user: "{{ sudo_test_user }}"
template:
src: "bar.j2"
dest: "~/bar.txt"
- name: check that the path in the user's home dir was created
stat:
path: "~{{ sudo_test_user }}/bar.txt"
register: results
- assert:
that:
- "results.stat.exists == True"
- name: Remove test user and their home dir
user:
name: "{{ sudo_test_user }}"
state: "absent"
remove: "yes"

View File

@ -0,0 +1 @@
{{ sudo_test_user }}

View File

@ -0,0 +1 @@
sudo_test_user: ansibletest1

View File

@ -18,11 +18,11 @@
- name: clean out the test directory
local_action: file name={{ output_dir|mandatory }} state=absent
tags: me
run_once: true
- name: create the test directory
local_action: file name={{ output_dir }} state=directory
tags: me
run_once: true
- name: fetch a small file
fetch: src="C:/Windows/win.ini" dest={{ output_dir }}
@ -145,7 +145,7 @@
- "not fetch_missing_nofail|changed"
- name: attempt to fetch a non-existent file - fail on missing
fetch: src="C:/this_file_should_not_exist.txt" dest={{ output_dir }} fail_on_missing=yes
fetch: src="~/this_file_should_not_exist.txt" dest={{ output_dir }} fail_on_missing=yes
register: fetch_missing
ignore_errors: true
@ -164,5 +164,6 @@
- name: check fetch directory result
assert:
that:
- "fetch_dir|failed"
# Doesn't fail anymore, only returns a message.
- "not fetch_dir|changed"
- "fetch_dir.msg"

View File

@ -4,6 +4,8 @@
- vars_var: "vars_var"
- param_var: "BAD!"
- vars_files_var: "BAD!"
- extra_var_override_once_removed: "{{ extra_var_override }}"
- from_inventory_once_removed: "{{ inven_var | default('BAD!') }}"
vars_files:
- vars/test_var_precedence.yml
roles:
@ -15,17 +17,22 @@
- name: use set_fact to override the registered_var
set_fact: registered_var="this is from set_fact"
- debug: var=extra_var
- debug: var=extra_var_override_once_removed
- debug: var=vars_var
- debug: var=vars_files_var
- debug: var=vars_files_var_role
- debug: var=registered_var
- debug: var=from_inventory_once_removed
- assert:
that:
- 'extra_var == "extra_var"'
- 'extra_var_override == "extra_var_override"'
- 'extra_var_override_once_removed == "extra_var_override"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'vars_files_var_role == "vars_files_var_role3"'
- 'registered_var == "this is from set_fact"'
- 'from_inventory_once_removed == "inventory_var"'
- hosts: inven_overridehosts
vars_files:

View File

@ -566,17 +566,9 @@ class TestUtils(unittest.TestCase):
def test_listify_lookup_plugin_terms(self):
basedir = os.path.dirname(__file__)
# Straight lookups
self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=[])), [])
self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['one', 'two'])), ['one', 'two'])
# Variable interpolation
self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['{{ foo }}', '{{ bar }}'], foo="hello", bar="world")),
['hello', 'world'])
with self.assertRaises(ansible.errors.AnsibleError) as ex:
ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['{{ foo }}', '{{ bar_typo }}'], foo="hello", bar="world"))
self.assertTrue("undefined variable in items: 'bar_typo'" in ex.exception.msg)
#self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=[])), [])
#self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['one', 'two'])), ['one', 'two'])
def test_deprecated(self):
sys_stderr = sys.stderr