1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/win_template/tasks/main.yml

115 lines
3.8 KiB
YAML
Raw Normal View History

# test code for the template module
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.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/>.
- name: fill in a basic template
# win_template: src=foo.j2 dest={{win_output_dir}}/foo.templated mode=0644
win_template: src=foo.j2 dest={{win_output_dir}}/foo.templated
register: template_result
- assert:
that:
- "'changed' in template_result"
# - "'dest' in template_result"
# - "'group' in template_result"
# - "'gid' in template_result"
# - "'checksum' in template_result"
# - "'owner' in template_result"
# - "'size' in template_result"
# - "'src' in template_result"
# - "'state' in template_result"
# - "'uid' in template_result"
- name: verify that the file was marked as changed
assert:
that:
- "template_result.changed == true"
- name: fill in a basic template again
win_template:
src: foo.j2
dest: "{{win_output_dir}}/foo.templated"
register: template_result2
- name: verify that the template was not changed
assert:
that:
- "not template_result2|changed"
# VERIFY CONTENTS
- name: copy known good into place
Fixes for WinRM/PowerShell support in v2. - Add support for inserting module args into PowerShell modules. Fixes #11661. - Support Windows paths containing spaces. Applies changes from #10727 to v2. Fixes #9999. Should also fix ansible/ansible-modules-core#944 and ansible/ansible-modules-core#1007. - Change how execution policy is set for running remote scripts. Applies changes from #11092 to v2. Also fixes ansible/ansible-modules-core#1776. - Use codepage 65001 (UTF-8) for WinRM connection instead of default (CP437), convert command to UTF-8 and results from UTF-8. Replaces changes from #10024. Fixes #11198. - Close WinRM connection when task completes. - Use win_stat, win_file and win_copy modules instead of stat, file and copy when called from within other action plugins (only when using WinRM+PowerShell). - Unquote Windows path arguments before passing to win_stat, win_file, win_copy and slurp modules (only when using WinRM/PowerShell). - Check for win_ping module to determine if core modules are missing (only when using WinRM/PowerShell). - Add stdout_lines to result from running low level commands (so stdout_lines is available when using raw/script). - Update copy action plugin to use shell functions for joining paths and checking for trailing slash. - Update fetch action plugin to unquote source path when using Windows paths. - Add win_copy and win_template action plugins that inherit from copy and template. - Support running .bat and .cmd scripts using default system encoding instead of UTF-8. - Always send PowerShell commands as base64-encoded blobs to allow for running simple PowerShell commands via raw. - Support running modules on Windows with interpreters other than PowerShell. - Update integration tests to support above changes and test unicode fixes. - Add test for win_user error from ansible/ansible-modules-core#1241 (fixed by ansible/ansible-modules-core#1774). - Add test for additional win_stat output values (implemented by ansible/ansible-modules-core#1473). - Add test for OS architecture and name from setup.ps1 (implemented by ansible/ansible-modules-core#1100). All WinRM integration tests pass for me with these changes.
2015-07-24 18:39:54 +02:00
win_copy: src=foo.txt dest={{win_output_dir}}\\foo.txt
- name: compare templated file to known good
raw: fc.exe {{win_output_dir}}\\foo.templated {{win_output_dir}}\\foo.txt
register: diff_result
- debug: var=diff_result
- name: verify templated file matches known good
assert:
that:
# - 'diff_result.stdout == ""'
- 'diff_result.stdout_lines[1] == "FC: no differences encountered"'
- "diff_result.rc == 0"
# VERIFY MODE
# can't set file mode on windows so commenting this test out
#- name: set file mode
# win_file: path={{win_output_dir}}/foo.templated mode=0644
# register: file_result
#- name: ensure file mode did not change
# assert:
# that:
# - "file_result.changed != True"
# commenting out all the following tests as expanduser and file modes not windows concepts.
# VERIFY dest as a directory does not break file attributes
# Note: expanduser is needed to go down the particular codepath that was broken before
#- name: setup directory for test
# win_file: state=directory dest={{win_output_dir | expanduser}}/template-dir mode=0755 owner=nobody group=root
#- name: set file mode when the destination is a directory
# win_template: src=foo.j2 dest={{win_output_dir | expanduser}}/template-dir/ mode=0600 owner=root group=root
#- name: set file mode when the destination is a directory
# win_template: src=foo.j2 dest={{win_output_dir | expanduser}}/template-dir/ mode=0600 owner=root group=root
# register: file_result
#
#- name: check that the file has the correct attributes
# win_stat: path={{win_output_dir | expanduser}}/template-dir/foo.j2
# register: file_attrs
#
#- assert:
# that:
# - "file_attrs.stat.uid == 0"
# - "file_attrs.stat.pw_name == 'root'"
# - "file_attrs.stat.mode == '0600'"
#
#- name: check that the containing directory did not change attributes
# win_stat: path={{win_output_dir | expanduser}}/template-dir/
# register: dir_attrs
#
#- assert:
# that:
# - "dir_attrs.stat.uid != 0"
# - "dir_attrs.stat.pw_name == 'nobody'"
# - "dir_attrs.stat.mode == '0755'"