Fix integration tests to support remote hosts.

This commit is contained in:
Matt Clay 2019-01-24 19:25:06 -08:00
parent 92b475f721
commit d2a7cc0b9f
37 changed files with 321 additions and 225 deletions

View file

@ -1,5 +1,5 @@
- name: simple block test
hosts: localhost
hosts: testhost
gather_facts: yes
strategy: "{{test_strategy|default('linear')}}"
vars:

View file

@ -4,7 +4,7 @@ set -eux
# ignore empty env var and use default
# shellcheck disable=SC1007
ANSIBLE_TIMEOUT= ansible -m ping localhost "$@"
ANSIBLE_TIMEOUT= ansible -m ping testhost -i ../../inventory "$@"
# env var is wrong type, this should be a fatal error pointing at the setting
ANSIBLE_TIMEOUT='lola' ansible -m ping localhost "$@" 2>&1|grep 'Invalid type for configuration option setting: DEFAULT_TIMEOUT'
ANSIBLE_TIMEOUT='lola' ansible -m ping testhost -i ../../inventory "$@" 2>&1|grep 'Invalid type for configuration option setting: DEFAULT_TIMEOUT'

View file

@ -1,2 +1,3 @@
dependencies:
- prepare_tests
- setup_remote_tmp_dir

View file

@ -17,10 +17,10 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: create a file that we can use to fetch
copy: content="test" dest={{ output_dir }}/orig
copy: content="test" dest={{ remote_tmp_dir }}/orig
- name: fetch the motd
fetch: src={{ output_dir }}/orig dest={{ output_dir }}/fetched
fetch: src={{ remote_tmp_dir }}/orig dest={{ output_dir }}/fetched
register: fetched
- debug: var=fetched
@ -31,22 +31,14 @@
- 'fetched["changed"] == True'
- 'fetched["checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
- 'fetched["remote_checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
- 'lookup("file", output_dir + "/fetched/" + inventory_hostname + remote_tmp_dir + "/orig") == "test"'
# TODO: check the become and non-become forms of fetch because in one form we'll do
# the get method of the connection plugin and in the become case we'll use the
# fetch module.
- name: diff what we fetched with the original file
shell: diff {{ output_dir }}/orig {{ output_dir }}/fetched/{{inventory_hostname}}{{ output_dir | expanduser }}/orig
register: diff
- name: check the diff to make sure they are the same
assert:
that:
'diff.stdout == ""'
- name: fetch a second time to show idempotence
fetch: src={{ output_dir }}/orig dest={{ output_dir }}/fetched
fetch: src={{ remote_tmp_dir }}/orig dest={{ output_dir }}/fetched
register: fetched
- name: Assert that the file was not fetched the second time
@ -56,7 +48,7 @@
- 'fetched["checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
- name: attempt to fetch a non-existent file - do not fail on missing
fetch: src={{ output_dir }}/doesnotexist dest={{ output_dir }}/fetched fail_on_missing=False
fetch: src={{ remote_tmp_dir }}/doesnotexist dest={{ output_dir }}/fetched fail_on_missing=False
register: fetch_missing_nofail
- name: check fetch missing no fail result
@ -66,7 +58,7 @@
- "fetch_missing_nofail is not changed"
- name: attempt to fetch a non-existent file - fail on missing
fetch: src={{ output_dir }}/doesnotexist dest={{ output_dir }}/fetched fail_on_missing=yes
fetch: src={{ remote_tmp_dir }}/doesnotexist dest={{ output_dir }}/fetched fail_on_missing=yes
register: fetch_missing
ignore_errors: true
@ -78,7 +70,7 @@
- "fetch_missing is not changed"
- name: attempt to fetch a non-existent file - fail on missing implicit
fetch: src={{ output_dir }}/doesnotexist dest={{ output_dir }}/fetched
fetch: src={{ remote_tmp_dir }}/doesnotexist dest={{ output_dir }}/fetched
register: fetch_missing_implicit
ignore_errors: true
@ -90,7 +82,7 @@
- "fetch_missing_implicit is not changed"
- name: attempt to fetch a directory - should not fail but return a message
fetch: src={{ output_dir }} dest={{ output_dir }}/somedir fail_on_missing=False
fetch: src={{ remote_tmp_dir }} dest={{ output_dir }}/somedir fail_on_missing=False
register: fetch_dir
- name: check fetch directory result
@ -100,7 +92,7 @@
- "fetch_dir.msg"
- name: attempt to fetch a directory - should fail
fetch: src={{ output_dir }} dest={{ output_dir }}/somedir fail_on_missing=True
fetch: src={{ remote_tmp_dir }} dest={{ output_dir }}/somedir fail_on_missing=True
register: failed_fetch_dir
ignore_errors: true
@ -112,32 +104,31 @@
- name: create symlink to a file that we can fetch
file:
path: "{{ output_dir }}/link"
src: "{{ output_dir }}/orig"
path: "{{ remote_tmp_dir }}/link"
src: "{{ remote_tmp_dir }}/orig"
state: "link"
- name: fetch the file via a symlink
fetch: src={{ output_dir }}/link dest={{ output_dir }}/fetched-link
fetch: src={{ remote_tmp_dir }}/link dest={{ output_dir }}/fetched-link
register: fetched
- debug: var=fetched
- name: Assert that we fetched correctly
assert:
that:
- 'fetched["changed"] == True'
- 'fetched["checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
- 'fetched["remote_checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
- 'lookup("file", output_dir + "/fetched-link/" + inventory_hostname + remote_tmp_dir + "/link") == "test"'
# TODO: check the become and non-become forms of fetch because in one form we'll do
# the get method of the connection plugin and in the become case we'll use the
# fetch module.
- name: diff what we fetched with the original file
shell: diff {{ output_dir }}/orig {{ output_dir }}/fetched-link/{{inventory_hostname}}{{ output_dir | expanduser }}/link
register: diff
- name: check the diff to make sure they are the same
assert:
that:
'diff.stdout == ""'
- name: dest is an existing directory name without trailing slash and flat=yes, should fail
fetch:
src: "{{ output_dir }}/orig"
src: "{{ remote_tmp_dir }}/orig"
dest: "{{ output_dir }}"
flat: yes
register: failed_fetch_dest_dir

View file

@ -1,3 +1,4 @@
dependencies:
- prepare_tests
- prepare_http_tests
- setup_remote_tmp_dir

View file

@ -33,8 +33,8 @@
- name: Define test files for file schema
set_fact:
geturl_srcfile: "{{ output_dir }}/aurlfile.txt"
geturl_dstfile: "{{ output_dir }}/aurlfile_copy.txt"
geturl_srcfile: "{{ remote_tmp_dir }}/aurlfile.txt"
geturl_dstfile: "{{ remote_tmp_dir }}/aurlfile_copy.txt"
- name: Create source file
copy:
@ -69,7 +69,7 @@
- name: test HTTP HEAD request for file in check mode
get_url:
url: "https://{{ httpbin_host }}/get"
dest: "{{ output_dir }}/get_url_check.txt"
dest: "{{ remote_tmp_dir }}/get_url_check.txt"
force: yes
check_mode: True
register: result
@ -83,7 +83,7 @@
- name: test HTTP HEAD for nonexistent URL in check mode
get_url:
url: "https://{{ httpbin_host }}/DOESNOTEXIST"
dest: "{{ output_dir }}/shouldnotexist.html"
dest: "{{ remote_tmp_dir }}/shouldnotexist.html"
force: yes
check_mode: True
register: result
@ -95,7 +95,7 @@
- result is failed
- name: test https fetch
get_url: url="https://{{ httpbin_host }}/get" dest={{output_dir}}/get_url.txt force=yes
get_url: url="https://{{ httpbin_host }}/get" dest={{remote_tmp_dir}}/get_url.txt force=yes
register: result
- name: assert the get_url call was successful
@ -107,12 +107,12 @@
- name: test https fetch to a site with mismatched hostname and certificate
get_url:
url: "https://{{ badssl_host }}/"
dest: "{{ output_dir }}/shouldnotexist.html"
dest: "{{ remote_tmp_dir }}/shouldnotexist.html"
ignore_errors: True
register: result
- stat:
path: "{{ output_dir }}/shouldnotexist.html"
path: "{{ remote_tmp_dir }}/shouldnotexist.html"
register: stat_result
- name: Assert that the file was not downloaded
@ -125,12 +125,12 @@
- name: test https fetch to a site with mismatched hostname and certificate and validate_certs=no
get_url:
url: "https://{{ badssl_host }}/"
dest: "{{ output_dir }}/get_url_no_validate.html"
dest: "{{ remote_tmp_dir }}/get_url_no_validate.html"
validate_certs: no
register: result
- stat:
path: "{{ output_dir }}/get_url_no_validate.html"
path: "{{ remote_tmp_dir }}/get_url_no_validate.html"
register: stat_result
- name: Assert that the file was downloaded
@ -144,11 +144,11 @@
- name: Test that SNI works
get_url:
url: 'https://{{ sni_host }}/'
dest: "{{ output_dir }}/sni.html"
dest: "{{ remote_tmp_dir }}/sni.html"
register: get_url_result
ignore_errors: True
- command: "grep '{{ sni_host }}' {{ output_dir}}/sni.html"
- command: "grep '{{ sni_host }}' {{ remote_tmp_dir}}/sni.html"
register: data_result
when: python_has_ssl_context
@ -173,11 +173,11 @@
- name: Test that SNI works
get_url:
url: 'https://{{ sni_host }}/'
dest: "{{ output_dir }}/sni.html"
dest: "{{ remote_tmp_dir }}/sni.html"
register: get_url_result
ignore_errors: True
- command: "grep '{{ sni_host }}' {{ output_dir}}/sni.html"
- command: "grep '{{ sni_host }}' {{ remote_tmp_dir}}/sni.html"
register: data_result
when: python_has_ssl_context
@ -202,17 +202,17 @@
- name: Test get_url with redirect
get_url:
url: 'https://{{ httpbin_host }}/redirect/6'
dest: "{{ output_dir }}/redirect.json"
dest: "{{ remote_tmp_dir }}/redirect.json"
- name: Test that setting file modes work
get_url:
url: 'https://{{ httpbin_host }}/'
dest: '{{ output_dir }}/test'
dest: '{{ remote_tmp_dir }}/test'
mode: '0707'
register: result
- stat:
path: "{{ output_dir }}/test"
path: "{{ remote_tmp_dir }}/test"
register: stat_result
- name: Assert that the file has the right permissions
@ -224,12 +224,12 @@
- name: Test that setting file modes on an already downlaoded file work
get_url:
url: 'https://{{ httpbin_host }}/'
dest: '{{ output_dir }}/test'
dest: '{{ remote_tmp_dir }}/test'
mode: '0070'
register: result
- stat:
path: "{{ output_dir }}/test"
path: "{{ remote_tmp_dir }}/test"
register: stat_result
- name: Assert that the file has the right permissions
@ -242,13 +242,13 @@
- name: Change mode on an already downloaded file and specify checksum
get_url:
url: 'https://{{ httpbin_host }}/get'
dest: '{{ output_dir }}/test'
dest: '{{ remote_tmp_dir }}/test'
checksum: 'sha256:7036ede810fad2b5d2e7547ec703cae8da61edbba43c23f9d7203a0239b765c4.'
mode: '0775'
register: result
- stat:
path: "{{ output_dir }}/test"
path: "{{ remote_tmp_dir }}/test"
register: stat_result
- name: Assert that file permissions on already downloaded file were changed
@ -260,7 +260,7 @@
- name: Get a file that already exists
get_url:
url: 'https://{{ httpbin_host }}/get'
dest: '{{ output_dir }}/test'
dest: '{{ remote_tmp_dir }}/test'
register: result
- name: Assert that we didn't re-download unnecessarily
@ -273,7 +273,7 @@
- name: set role facts
set_fact:
http_port: 27617
files_dir: '{{ output_dir }}/files'
files_dir: '{{ remote_tmp_dir }}/files'
- name: create files_dir
file:
@ -326,44 +326,44 @@
- copy:
src: "testserver.py"
dest: "{{ output_dir }}/testserver.py"
dest: "{{ remote_tmp_dir }}/testserver.py"
- name: start SimpleHTTPServer for issues 27617
shell: cd {{ files_dir }} && {{ ansible_python.executable }} {{ output_dir}}/testserver.py {{ http_port }}
shell: cd {{ files_dir }} && {{ ansible_python.executable }} {{ remote_tmp_dir}}/testserver.py {{ http_port }}
async: 90
poll: 0
- name: download src with sha1 checksum url
get_url:
url: 'http://localhost:{{ http_port }}/27617.txt'
dest: '{{ output_dir }}'
dest: '{{ remote_tmp_dir }}'
checksum: 'sha1:http://localhost:{{ http_port }}/sha1sum.txt'
register: result_sha1
- stat:
path: "{{ output_dir }}/27617.txt"
path: "{{ remote_tmp_dir }}/27617.txt"
register: stat_result_sha1
- name: download src with sha256 checksum url
get_url:
url: 'http://localhost:{{ http_port }}/27617.txt'
dest: '{{ output_dir }}/27617sha256.txt'
dest: '{{ remote_tmp_dir }}/27617sha256.txt'
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum.txt'
register: result_sha256
- stat:
path: "{{ output_dir }}/27617.txt"
path: "{{ remote_tmp_dir }}/27617.txt"
register: stat_result_sha256
- name: download src with sha256 checksum url with dot leading paths
get_url:
url: 'http://localhost:{{ http_port }}/27617.txt'
dest: '{{ output_dir }}/27617sha256_with_dot.txt'
dest: '{{ remote_tmp_dir }}/27617sha256_with_dot.txt'
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_dot.txt'
register: result_sha256_with_dot
- stat:
path: "{{ output_dir }}/27617sha256_with_dot.txt"
path: "{{ remote_tmp_dir }}/27617sha256_with_dot.txt"
register: stat_result_sha256_with_dot
- name: Assert that the file was downloaded
@ -380,25 +380,30 @@
- name: Test url split with no filename
get_url:
url: https://{{ httpbin_host }}
dest: "{{ output_dir }}"
dest: "{{ remote_tmp_dir }}"
- name: Test headers string
get_url:
url: https://{{ httpbin_host }}/headers
headers: Foo:bar,Baz:qux
dest: "{{ output_dir }}/headers_string.json"
dest: "{{ remote_tmp_dir }}/headers_string.json"
- name: Get downloaded file
slurp:
src: "{{ remote_tmp_dir }}/headers_string.json"
register: result
- name: Test headers string
assert:
that:
- (lookup('file', output_dir ~ '/headers_string.json')|from_json).headers.get('Foo') == 'bar'
- (lookup('file', output_dir ~ '/headers_string.json')|from_json).headers.get('Baz') == 'qux'
- (result["content"] | b64decode | from_json).headers.get('Foo') == 'bar'
- (result["content"] | b64decode | from_json).headers.get('Baz') == 'qux'
- name: Test headers string invalid format
get_url:
url: https://{{ httpbin_host }}/headers
headers: Foo
dest: "{{ output_dir }}/headers_string_invalid.json"
dest: "{{ remote_tmp_dir }}/headers_string_invalid.json"
register: invalid_string_headers
failed_when:
- invalid_string_headers is successful
@ -410,24 +415,34 @@
headers:
Foo: bar
Baz: qux
dest: "{{ output_dir }}/headers_dict.json"
dest: "{{ remote_tmp_dir }}/headers_dict.json"
- name: Get downloaded file
slurp:
src: "{{ remote_tmp_dir }}/headers_dict.json"
register: result
- name: Test headers dict
assert:
that:
- (lookup('file', output_dir ~ '/headers_dict.json')|from_json).headers.get('Foo') == 'bar'
- (lookup('file', output_dir ~ '/headers_dict.json')|from_json).headers.get('Baz') == 'qux'
- (result["content"] | b64decode | from_json).headers.get('Foo') == 'bar'
- (result["content"] | b64decode | from_json).headers.get('Baz') == 'qux'
- name: Test client cert auth, with certs
get_url:
url: "https://ansible.http.tests/ssl_client_verify"
client_cert: "{{ output_dir }}/client.pem"
client_key: "{{ output_dir }}/client.key"
dest: "{{ output_dir }}/ssl_client_verify"
client_cert: "{{ remote_tmp_dir }}/client.pem"
client_key: "{{ remote_tmp_dir }}/client.key"
dest: "{{ remote_tmp_dir }}/ssl_client_verify"
when: has_httptester
- name: Get downloaded file
slurp:
src: "{{ remote_tmp_dir }}/ssl_client_verify"
register: result
- name: Assert that the ssl_client_verify file contains the correct content
assert:
that:
- 'lookup("file", "{{ output_dir }}/ssl_client_verify") == "ansible.http.tests:SUCCESS"'
- '(result["content"] | b64decode) == "ansible.http.tests:SUCCESS"'
when: has_httptester

View file

@ -161,10 +161,15 @@
register: git_fetch
ignore_errors: yes
- name: DEPTH | get "a" file
slurp:
src: '{{ checkout_dir }}/a'
register: a_file
- name: DEPTH | check update arrived
assert:
that:
- "{{ lookup('file', checkout_dir+'/a' )}} == 3"
- "{{ a_file['content'] | b64decode | trim }} == 3"
- git_fetch is changed
- name: DEPTH | clear checkout_dir

View file

@ -39,10 +39,15 @@
register: git_fetch_force
ignore_errors: yes
- name: LOCALMODS | get "a" file
slurp:
src: '{{ checkout_dir }}/a'
register: a_file
- name: LOCALMODS | check update arrived
assert:
that:
- "{{ lookup('file', checkout_dir+'/a' )}} == 2"
- "{{ a_file['content'] | b64decode | trim }} == 2"
- git_fetch_force is changed
- name: LOCALMODS | clear checkout_dir
@ -92,10 +97,15 @@
register: git_fetch_force
ignore_errors: yes
- name: LOCALMODS | get "a" file
slurp:
src: '{{ checkout_dir }}/a'
register: a_file
- name: LOCALMODS | check update arrived
assert:
that:
- "{{ lookup('file', checkout_dir+'/a' )}} == 2"
- "{{ a_file['content'] | b64decode | trim }} == 2"
- git_fetch_force is changed
- name: LOCALMODS | clear checkout_dir

View file

@ -1,4 +1,4 @@
- hosts: localhost
- hosts: testhost
tasks:
- include: test_includes4.yml
with_items: ["a"]

View file

@ -6,8 +6,6 @@
vault_uri: 'https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/lookup_hashi_vault/vault_{{ vault_version }}_{{ ansible_system | lower }}_{{ vault_arch }}.zip'
vault_cmd: '{{ local_temp_dir }}/vault'
connection: local # already defined in inventory for testhost, usefull when used with another inventory
block:
- name: Create a local temporary directory
tempfile:

View file

@ -1,4 +1,4 @@
- hosts: testhost
- hosts: localhost
tasks:
- name: Install openssl
import_role:

View file

@ -1,4 +1,4 @@
- hosts: testhost
- hosts: localhost
tasks:
- name: register pyOpenSSL version
command: "{{ ansible_python.executable }} -c 'import OpenSSL; print(OpenSSL.__version__)'"

View file

@ -18,8 +18,8 @@ set -eux
ANSIBLE_ROLES_PATH=../ \
ANSIBLE_CONFIG=../../integration.cfg \
ansible-playbook -i ../../inventory -e@../../integration_config.yml playbooks/install_dependencies.yml -v "$@"
ansible-playbook -e@../../integration_config.yml playbooks/install_dependencies.yml -v "$@"
ANSIBLE_ROLES_PATH=../ \
ANSIBLE_CONFIG=../../integration.cfg \
ansible-playbook -i ../../inventory -e@../../integration_config.yml playbooks/test_lookup_hashi_vault.yml -v "$@"
ansible-playbook -e@../../integration_config.yml playbooks/test_lookup_hashi_vault.yml -v "$@"

View file

@ -1,2 +1,3 @@
dependencies:
- setup_mysql_db
- setup_remote_tmp_dir

View file

@ -18,11 +18,19 @@
- foo
- bar
- name: Copy SQL scripts to remote
copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/{{ item | basename }}"
with_items:
- create-function.sql
- create-procedure.sql
- name: Create function for test
shell: "mysql < {{ role_path }}/files/create-function.sql"
shell: "mysql < {{ remote_tmp_dir }}/create-function.sql"
- name: Create procedure for test
shell: "mysql < {{ role_path }}/files/create-procedure.sql"
shell: "mysql < {{ remote_tmp_dir }}/create-procedure.sql"
- name: Create user with FUNCTION and PROCEDURE privileges
mysql_user:

View file

@ -0,0 +1,2 @@
dependencies:
- setup_remote_tmp_dir

View file

@ -37,7 +37,7 @@
- name: Get client cert/key
get_url:
url: "http://ansible.http.tests/{{ item }}"
dest: "{{ output_dir }}/{{ item }}"
dest: "{{ remote_tmp_dir }}/{{ item }}"
when: ansible_os_family != 'Windows'
with_items:
- client.pem

View file

@ -0,0 +1,2 @@
dependencies:
- setup_remote_tmp_dir

View file

@ -16,8 +16,15 @@
state: directory
mode: 0755
- name: Copy package specs to remote
copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/{{ item | basename }}"
with_fileglob:
- "files/package_specs/*"
- name: Create deb files
shell: "equivs-build {{ item }}"
shell: "equivs-build {{ remote_tmp_dir }}/{{ item | basename }}"
args:
chdir: "{{ repodir }}"
with_fileglob:

View file

@ -0,0 +1,2 @@
dependencies:
- setup_remote_constraints

View file

@ -16,7 +16,7 @@
pip:
state: present
name: 'docker{{ extra_packages }}'
extra_args: "-c {{ role_path }}/../../../runner/requirements/constraints.txt"
extra_args: "-c {{ remote_constraints }}"
# Detect docker CLI, API and docker-py versions
- name: Check Docker CLI version

View file

@ -0,0 +1,2 @@
dependencies:
- setup_remote_tmp_dir

View file

@ -0,0 +1,8 @@
- name: record constraints.txt path on remote host
set_fact:
remote_constraints: "{{ remote_tmp_dir }}/constraints.txt"
- name: copy constraints.txt to remote host
copy:
src: "{{ role_path }}/../../../runner/requirements/constraints.txt"
dest: "{{ remote_constraints }}"

View file

@ -0,0 +1,9 @@
- name: delete temporary directory
file:
path: "{{ remote_tmp_dir }}"
state: absent
- name: delete temporary directory (windows)
win_file:
path: "{{ remote_tmp_dir }}"
state: absent

View file

@ -0,0 +1,11 @@
- name: create temporary directory
tempfile:
state: directory
suffix: .test
register: remote_tmp_dir
notify:
- delete temporary directory
- name: record temporary directory
set_fact:
remote_tmp_dir: "{{ remote_tmp_dir.path }}"

View file

@ -0,0 +1,10 @@
- name: make sure we have the ansible_os_family and ansible_distribution_version facts
setup:
gather_subset: distribution
when: ansible_facts == {}
- include_tasks: "{{ lookup('first_found', files)}}"
vars:
files:
- "{{ ansible_os_family | lower }}.yml"
- "default.yml"

View file

@ -0,0 +1,11 @@
- name: create temporary directory
win_tempfile:
state: directory
suffix: .test
register: remote_tmp_dir
notify:
- delete temporary directory (windows)
- name: record temporary directory
set_fact:
remote_tmp_dir: "{{ remote_tmp_dir.path }}"

View file

@ -1,2 +1,3 @@
dependencies:
- prepare_tests
- setup_remote_tmp_dir

View file

@ -35,34 +35,34 @@
when: ansible_pkg_mgr == 'pkgng'
- name: prep our file
copy: src=foo.txt dest={{output_dir}}/foo-unarchive.txt
copy: src=foo.txt dest={{remote_tmp_dir}}/foo-unarchive.txt
- name: prep a tar file
shell: tar cvf test-unarchive.tar foo-unarchive.txt chdir={{output_dir}}
shell: tar cvf test-unarchive.tar foo-unarchive.txt chdir={{remote_tmp_dir}}
- name: prep a tar.gz file
shell: tar czvf test-unarchive.tar.gz foo-unarchive.txt chdir={{output_dir}}
shell: tar czvf test-unarchive.tar.gz foo-unarchive.txt chdir={{remote_tmp_dir}}
- name: prep a chmodded file for zip
copy: src=foo.txt dest={{output_dir}}/foo-unarchive-777.txt mode=0777
copy: src=foo.txt dest={{remote_tmp_dir}}/foo-unarchive-777.txt mode=0777
- name: prep a windows permission file for our zip
copy: src=foo.txt dest={{output_dir}}/FOO-UNAR.TXT
copy: src=foo.txt dest={{remote_tmp_dir}}/FOO-UNAR.TXT
# This gets around an unzip timestamp bug in some distributions
# Recent unzip on Ubuntu and BSD will randomly round some timestamps up.
# But that doesn't seem to happen when the timestamp has an even second.
- name: Bug work around
command: touch -t "201705111530.00" {{output_dir}}/foo-unarchive.txt {{output_dir}}/foo-unarchive-777.txt {{output_dir}}/FOO-UNAR.TXT
command: touch -t "201705111530.00" {{remote_tmp_dir}}/foo-unarchive.txt {{remote_tmp_dir}}/foo-unarchive-777.txt {{remote_tmp_dir}}/FOO-UNAR.TXT
# See Ubuntu bug 1691636: https://bugs.launchpad.net/ubuntu/+source/unzip/+bug/1691636
# When these are fixed, this code should be removed.
- name: prep a zip file
shell: zip test-unarchive.zip foo-unarchive.txt foo-unarchive-777.txt chdir={{output_dir}}
shell: zip test-unarchive.zip foo-unarchive.txt foo-unarchive-777.txt chdir={{remote_tmp_dir}}
- name: Prepare - Create test dirs
file:
path: "{{output_dir}}/{{item}}"
path: "{{remote_tmp_dir}}/{{item}}"
state: directory
with_items:
- created/include
@ -71,7 +71,7 @@
- name: Prepare - Create test files
file:
path: "{{output_dir}}/created/{{item}}"
path: "{{remote_tmp_dir}}/created/{{item}}"
state: touch
with_items:
- include/include-1.txt
@ -88,28 +88,28 @@
- other/other-2.ext
- name: Prepare - zip file
shell: zip -r {{output_dir}}/unarchive-00.zip * chdir={{output_dir}}/created/
shell: zip -r {{remote_tmp_dir}}/unarchive-00.zip * chdir={{remote_tmp_dir}}/created/
- name: Prepare - tar file
shell: tar czvf {{output_dir}}/unarchive-00.tar * chdir={{output_dir}}/created/
shell: tar czvf {{remote_tmp_dir}}/unarchive-00.tar * chdir={{remote_tmp_dir}}/created/
- name: add a file with Windows permissions to zip file
shell: zip -k test-unarchive.zip FOO-UNAR.TXT chdir={{output_dir}}
shell: zip -k test-unarchive.zip FOO-UNAR.TXT chdir={{remote_tmp_dir}}
- name: prep a subdirectory
file: path={{output_dir}}/unarchive-dir state=directory
file: path={{remote_tmp_dir}}/unarchive-dir state=directory
- name: prep our file
copy: src=foo.txt dest={{output_dir}}/unarchive-dir/foo-unarchive.txt
copy: src=foo.txt dest={{remote_tmp_dir}}/unarchive-dir/foo-unarchive.txt
- name: prep a tar.gz file with directory
shell: tar czvf test-unarchive-dir.tar.gz unarchive-dir chdir={{output_dir}}
shell: tar czvf test-unarchive-dir.tar.gz unarchive-dir chdir={{remote_tmp_dir}}
- name: create our tar unarchive destination
file: path={{output_dir}}/test-unarchive-tar state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar state=directory
- name: unarchive a tar file
unarchive: src={{output_dir}}/test-unarchive.tar dest="{{output_dir | expanduser}}/test-unarchive-tar" remote_src=yes
unarchive: src={{remote_tmp_dir}}/test-unarchive.tar dest="{{remote_tmp_dir}}/test-unarchive-tar" remote_src=yes
register: unarchive01
- name: verify that the file was marked as changed
@ -118,16 +118,16 @@
- "unarchive01.changed == true"
- name: verify that the file was unarchived
file: path={{output_dir}}/test-unarchive-tar/foo-unarchive.txt state=file
file: path={{remote_tmp_dir}}/test-unarchive-tar/foo-unarchive.txt state=file
- name: remove our tar unarchive destination
file: path={{output_dir}}/test-unarchive-tar state=absent
file: path={{remote_tmp_dir}}/test-unarchive-tar state=absent
- name: create our tar.gz unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive a tar.gz file
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz remote_src=yes
unarchive: src={{remote_tmp_dir}}/test-unarchive.tar.gz dest={{remote_tmp_dir}}/test-unarchive-tar-gz remote_src=yes
register: unarchive02
- name: verify that the file was marked as changed
@ -138,16 +138,16 @@
- "'files' not in unarchive02"
- name: verify that the file was unarchived
file: path={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt state=file
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt state=file
- name: remove our tar.gz unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=absent
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=absent
- name: create our tar.gz unarchive destination for creates
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive a tar.gz file with creates set
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz remote_src=yes creates={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
unarchive: src={{remote_tmp_dir}}/test-unarchive.tar.gz dest={{remote_tmp_dir}}/test-unarchive-tar-gz remote_src=yes creates={{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
register: unarchive02b
- name: verify that the file was marked as changed
@ -156,10 +156,10 @@
- "unarchive02b.changed == true"
- name: verify that the file was unarchived
file: path={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt state=file
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt state=file
- name: unarchive a tar.gz file with creates over an existing file
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz remote_src=yes creates={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
unarchive: src={{remote_tmp_dir}}/test-unarchive.tar.gz dest={{remote_tmp_dir}}/test-unarchive-tar-gz remote_src=yes creates={{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
register: unarchive02c
- name: verify that the file was not marked as changed
@ -169,10 +169,10 @@
- name: unarchive a tar.gz file with creates over an existing file using complex_args
unarchive:
src: "{{output_dir}}/test-unarchive.tar.gz"
dest: "{{output_dir | expanduser}}/test-unarchive-tar-gz"
src: "{{remote_tmp_dir}}/test-unarchive.tar.gz"
dest: "{{remote_tmp_dir}}/test-unarchive-tar-gz"
remote_src: yes
creates: "{{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt"
creates: "{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt"
register: unarchive02d
- name: verify that the file was not marked as changed
@ -181,13 +181,13 @@
- "unarchive02d.changed == false"
- name: remove our tar.gz unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=absent
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=absent
- name: create our zip unarchive destination
file: path={{output_dir}}/test-unarchive-zip state=directory
file: path={{remote_tmp_dir}}/test-unarchive-zip state=directory
- name: unarchive a zip file
unarchive: src={{output_dir}}/test-unarchive.zip dest={{output_dir | expanduser}}/test-unarchive-zip remote_src=yes list_files=True
unarchive: src={{remote_tmp_dir}}/test-unarchive.zip dest={{remote_tmp_dir}}/test-unarchive-zip remote_src=yes list_files=True
register: unarchive03
- name: verify that the file was marked as changed
@ -202,14 +202,14 @@
- "'FOO-UNAR.TXT' in unarchive03['files']"
- name: verify that the file was unarchived
file: path={{output_dir}}/test-unarchive-zip/{{item}} state=file
file: path={{remote_tmp_dir}}/test-unarchive-zip/{{item}} state=file
with_items:
- foo-unarchive.txt
- foo-unarchive-777.txt
- FOO-UNAR.TXT
- name: repeat the last request to verify no changes
unarchive: src={{output_dir}}/test-unarchive.zip dest={{output_dir | expanduser}}/test-unarchive-zip remote_src=yes list_files=True
unarchive: src={{remote_tmp_dir}}/test-unarchive.zip dest={{remote_tmp_dir}}/test-unarchive-zip remote_src=yes list_files=True
register: unarchive03b
- name: verify that the task was not marked as changed
@ -217,18 +217,19 @@
that:
- "unarchive03b.changed == false"
- name: "Create {{ output_dir }}/exclude directory"
- name: "Create {{ remote_tmp_dir }}/exclude directory"
file:
state: directory
path: "{{ output_dir }}/exclude-{{item}}"
path: "{{ remote_tmp_dir }}/exclude-{{item}}"
with_items:
- zip
- tar
- name: Unpack archive file excluding regular and glob files.
unarchive:
src: "{{ output_dir }}/unarchive-00.{{item}}"
dest: "{{ output_dir }}/exclude-{{item}}"
src: "{{ remote_tmp_dir }}/unarchive-00.{{item}}"
dest: "{{ remote_tmp_dir }}/exclude-{{item}}"
remote_src: yes
exclude:
- "exclude/exclude-*.txt"
- "other/exclude-1.ext"
@ -237,7 +238,7 @@
- tar
- name: verify that the file was unarchived
shell: find {{ output_dir }}/exclude-{{item}} chdir={{ output_dir }}
shell: find {{ remote_tmp_dir }}/exclude-{{item}} chdir={{ remote_tmp_dir }}
register: unarchive00
with_items:
- zip
@ -252,10 +253,10 @@
- "{{ unarchive00.results }}"
- name: remove our zip unarchive destination
file: path={{output_dir}}/test-unarchive-zip state=absent
file: path={{remote_tmp_dir}}/test-unarchive-zip state=absent
- name: remove our test files for the archive
file: path={{output_dir}}/{{item}} state=absent
file: path={{remote_tmp_dir}}/{{item}} state=absent
with_items:
- foo-unarchive.txt
- foo-unarchive-777.txt
@ -271,7 +272,7 @@
when: unarchive04.stat.exists
- name: try unarchiving to /tmp
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest=/tmp remote_src=yes
unarchive: src={{remote_tmp_dir}}/test-unarchive.tar.gz dest=/tmp remote_src=yes
register: unarchive05
- name: verify that the file was marked as changed
@ -286,12 +287,12 @@
file: path=/tmp/foo-unarchive.txt state=absent
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive and set mode to 0600, directories 0700
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
remote_src: yes
mode: "u+rwX,g-rwx,o-rwx"
list_files: True
@ -299,7 +300,7 @@
- name: Test that the file modes were changed
stat:
path: "{{ output_dir | expanduser }}/test-unarchive-tar-gz/foo-unarchive.txt"
path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/foo-unarchive.txt"
register: unarchive06_stat
- name: Test that the file modes were changed
@ -313,22 +314,22 @@
- "'foo-unarchive.txt' in unarchive06['files']"
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
file: path={{ remote_tmp_dir }}/test-unarchive-tar-gz state=absent
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive over existing extraction and set mode to 0644
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
remote_src: yes
mode: "u+rwX,g-wx,o-wx,g+r,o+r"
register: unarchive06_2
- name: Test that the file modes were changed
stat:
path: "{{ output_dir | expanduser }}/test-unarchive-tar-gz/foo-unarchive.txt"
path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/foo-unarchive.txt"
register: unarchive06_2_stat
- debug: var=unarchive06_2_stat.stat.mode
@ -340,8 +341,8 @@
- name: Repeat the last request to verify no changes
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
remote_src: yes
mode: "u+rwX-x,g-wx,o-wx,g+r,o+r"
list_files: True
@ -357,15 +358,15 @@
- "'foo-unarchive.txt' in unarchive07['files']"
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
file: path={{ remote_tmp_dir }}/test-unarchive-tar-gz state=absent
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-zip state=directory
file: path={{remote_tmp_dir}}/test-unarchive-zip state=directory
- name: unarchive and set mode to 0601, directories 0700
unarchive:
src: "{{ output_dir }}/test-unarchive.zip"
dest: "{{ output_dir | expanduser }}/test-unarchive-zip"
src: "{{ remote_tmp_dir }}/test-unarchive.zip"
dest: "{{ remote_tmp_dir }}/test-unarchive-zip"
remote_src: yes
mode: "u+rwX-x,g-rwx,o=x"
list_files: True
@ -373,7 +374,7 @@
- name: Test that the file modes were changed
stat:
path: "{{ output_dir | expanduser }}/test-unarchive-zip/foo-unarchive.txt"
path: "{{ remote_tmp_dir }}/test-unarchive-zip/foo-unarchive.txt"
register: unarchive08_stat
- name: Test that the file modes were changed
@ -390,8 +391,8 @@
- name: unarchive zipfile a second time and set mode to 0601, directories 0700
unarchive:
src: "{{ output_dir }}/test-unarchive.zip"
dest: "{{ output_dir | expanduser }}/test-unarchive-zip"
src: "{{ remote_tmp_dir }}/test-unarchive.zip"
dest: "{{ remote_tmp_dir }}/test-unarchive-zip"
remote_src: yes
mode: "u+rwX-x,g-rwx,o=x"
list_files: True
@ -399,7 +400,7 @@
- name: Test that the file modes were not changed
stat:
path: "{{ output_dir | expanduser }}/test-unarchive-zip/foo-unarchive.txt"
path: "{{ remote_tmp_dir }}/test-unarchive-zip/foo-unarchive.txt"
register: unarchive08_stat
- debug:
@ -421,18 +422,18 @@
- "'FOO-UNAR.TXT' in unarchive08['files']"
- name: remove our zip unarchive destination
file: path={{ output_dir }}/test-unarchive-zip state=absent
file: path={{ remote_tmp_dir }}/test-unarchive-zip state=absent
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=directory
- name: create a directory with quotable chars
file: path="{{ output_dir }}/test-quotes~root" state=directory
file: path="{{ remote_tmp_dir }}/test-quotes~root" state=directory
- name: unarchive into directory with quotable chars
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
dest: "{{ output_dir | expanduser }}/test-quotes~root"
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/test-quotes~root"
remote_src: yes
register: unarchive08
@ -443,8 +444,8 @@
- name: unarchive into directory with quotable chars a second time
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
dest: "{{ output_dir | expanduser }}/test-quotes~root"
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/test-quotes~root"
remote_src: yes
register: unarchive09
@ -454,11 +455,11 @@
- "unarchive09.changed == false"
- name: remove quotable chars test
file: path="{{ output_dir }}/test-quotes~root" state=absent
file: path="{{ remote_tmp_dir }}/test-quotes~root" state=absent
- name: create our unarchive destination
file:
path: "{{ output_dir }}/test-unarchive-nonascii-くらとみ-tar-gz"
path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz"
state: directory
- name: test that unarchive works with an archive that contains non-ascii filenames
@ -466,14 +467,14 @@
# Both the filename of the tarball and the filename inside the tarball have
# nonascii chars
src: "test-unarchive-nonascii-くらとみ.tar.gz"
dest: "{{ output_dir }}/test-unarchive-nonascii-くらとみ-tar-gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz"
mode: "u+rwX,go+rX"
remote_src: no
register: nonascii_result0
- name: Check that file is really there
stat:
path: "{{ output_dir | expanduser }}/test-unarchive-nonascii-くらとみ-tar-gz/storage/àâæçéèïîôœ(copy)!@#$%^&-().jpg"
path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz/storage/àâæçéèïîôœ(copy)!@#$%^&-().jpg"
register: nonascii_stat0
- name: Assert that nonascii tests succeeded
@ -483,17 +484,17 @@
- "nonascii_stat0.stat.exists == true"
- name: remove nonascii test
file: path="{{ output_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" state=absent
file: path="{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" state=absent
# Test that unarchiving is performed if files are missing
# https://github.com/ansible/ansible-modules-core/issues/1064
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive a tar that has directories
unarchive:
src: "{{ output_dir }}/test-unarchive-dir.tar.gz"
dest: "{{ output_dir }}/test-unarchive-tar-gz"
src: "{{ remote_tmp_dir }}/test-unarchive-dir.tar.gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
mode: "0700"
remote_src: yes
register: unarchive10
@ -505,18 +506,18 @@
- name: Change the mode of the toplevel dir
file:
path: "{{ output_dir }}/test-unarchive-tar-gz/unarchive-dir"
path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/unarchive-dir"
mode: 0701
- name: Remove a file from the extraction point
file:
path: "{{ output_dir }}/test-unarchive-tar-gz/unarchive-dir/foo-unarchive.txt"
path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/unarchive-dir/foo-unarchive.txt"
state: absent
- name: unarchive a tar that has directories
unarchive:
src: "{{ output_dir }}/test-unarchive-dir.tar.gz"
dest: "{{ output_dir }}/test-unarchive-tar-gz"
src: "{{ remote_tmp_dir }}/test-unarchive-dir.tar.gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
mode: "0700"
remote_src: yes
register: unarchive10_1
@ -527,7 +528,7 @@
- "unarchive10_1.changed == true"
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
file: path={{ remote_tmp_dir }}/test-unarchive-tar-gz state=absent
#
# Symlink tests
@ -535,26 +536,26 @@
- name: Create a destination dir
file:
path: "{{ output_dir }}/test-unarchive-tar-gz"
path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
state: directory
- name: Create a symlink to the detination dir
file:
path: "{{ output_dir }}/link-to-unarchive-dir"
src: "{{ output_dir }}/test-unarchive-tar-gz"
path: "{{ remote_tmp_dir }}/link-to-unarchive-dir"
src: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
state: "link"
- name: test that unarchive works when dest is a symlink to a dir
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
dest: "{{ output_dir | expanduser }}/link-to-unarchive-dir"
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/link-to-unarchive-dir"
mode: "u+rwX,go+rX"
remote_src: yes
register: unarchive_11
- name: Check that file is really there
stat:
path: "{{ output_dir | expanduser }}/test-unarchive-tar-gz/foo-unarchive.txt"
path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/foo-unarchive.txt"
register: unarchive11_stat0
- name: Assert that unarchive when dest is a symlink to a dir worked
@ -564,23 +565,23 @@
- "unarchive11_stat0.stat.exists == true"
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
file: path={{ remote_tmp_dir }}/test-unarchive-tar-gz state=absent
- name: Create a file
file:
path: "{{ output_dir }}/test-unarchive-tar-gz"
path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
state: touch
- name: Create a symlink to the file
file:
path: "{{ output_dir }}/link-to-unarchive-file"
src: "{{ output_dir }}/test-unarchive-tar-gz"
path: "{{ remote_tmp_dir }}/link-to-unarchive-file"
src: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
state: "link"
- name: test that unarchive fails when dest is a link to a file
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
dest: "{{ output_dir | expanduser }}/link-to-unarchive-file"
src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
dest: "{{ remote_tmp_dir }}/link-to-unarchive-file"
mode: "u+rwX,go+rX"
remote_src: yes
ignore_errors: True
@ -592,16 +593,16 @@
- "unarchive_12.failed == true"
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
file: path={{ remote_tmp_dir }}/test-unarchive-tar-gz state=absent
# Test downloading a file before unarchiving it
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
file: path={{remote_tmp_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive a tar from an URL
unarchive:
src: "https://releases.ansible.com/ansible/ansible-latest.tar.gz"
dest: "{{ output_dir }}/test-unarchive-tar-gz"
dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
mode: "0700"
remote_src: yes
register: unarchive13
@ -612,4 +613,4 @@
- "unarchive13.changed == true"
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
file: path={{ remote_tmp_dir }}/test-unarchive-tar-gz state=absent

View file

@ -1,4 +1,3 @@
destructive
shippable/posix/group1
needs/httptester
needs/file/test/runner/requirements/constraints.txt

View file

@ -1,3 +1,5 @@
dependencies:
- prepare_tests
- prepare_http_tests
- setup_remote_tmp_dir
- setup_remote_constraints

View file

@ -285,7 +285,7 @@
pip:
name: "{{ item }}"
state: latest
extra_args: "-c {{ role_path }}/../../../runner/requirements/constraints.txt"
extra_args: "-c {{ remote_constraints }}"
with_items:
- urllib3
- PyOpenSSL
@ -402,8 +402,8 @@
- name: Test client cert auth, with certs
uri:
url: "https://ansible.http.tests/ssl_client_verify"
client_cert: "{{ output_dir }}/client.pem"
client_key: "{{ output_dir }}/client.key"
client_cert: "{{ remote_tmp_dir }}/client.pem"
client_key: "{{ remote_tmp_dir }}/client.key"
return_content: true
register: result
failed_when: result.content != "ansible.http.tests:SUCCESS"
@ -412,8 +412,8 @@
- name: Test client cert auth, with no validation
uri:
url: "https://fail.ansible.http.tests/ssl_client_verify"
client_cert: "{{ output_dir }}/client.pem"
client_key: "{{ output_dir }}/client.key"
client_cert: "{{ remote_tmp_dir }}/client.pem"
client_key: "{{ remote_tmp_dir }}/client.key"
return_content: true
validate_certs: no
register: result
@ -423,8 +423,8 @@
- name: Test client cert auth, with validation and ssl mismatch
uri:
url: "https://fail.ansible.http.tests/ssl_client_verify"
client_cert: "{{ output_dir }}/client.pem"
client_key: "{{ output_dir }}/client.key"
client_cert: "{{ remote_tmp_dir }}/client.pem"
client_key: "{{ remote_tmp_dir }}/client.key"
return_content: true
validate_certs: yes
register: result
@ -445,16 +445,13 @@
- name: Write out netrc template
template:
src: netrc.j2
dest: "{{ output_dir }}/netrc"
- debug:
msg: "{{ lookup('file', output_dir ~ '/netrc') }}"
dest: "{{ remote_tmp_dir }}/netrc"
- name: Test netrc with port
uri:
url: "https://{{ httpbin_host }}:443/basic-auth/user/passwd"
environment:
NETRC: "{{ output_dir|expanduser }}/netrc"
NETRC: "{{ remote_tmp_dir }}/netrc"
- name: Test JSON POST with src
uri:
@ -470,10 +467,15 @@
that:
- result.json.json[0] == 'JSON Test Pattern pass1'
- name: Copy file pass0.json to remote
copy:
src: "{{ role_path }}/files/pass0.json"
dest: "{{ remote_tmp_dir }}/pass0.json"
- name: Test JSON POST with src and remote_src=True
uri:
url: "https://{{ httpbin_host}}/post"
src: "{{ role_path }}/files/pass0.json"
src: "{{ remote_tmp_dir }}/pass0.json"
remote_src: true
method: POST
return_content: true

View file

@ -16,15 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
- name: get the jinja2 version
shell: python -c 'import jinja2; print(jinja2.__version__)'
register: jinja2_version
delegate_to: localhost
changed_when: no
- debug:
msg: "Jinja version: {{ jinja2_version.stdout }}, Python version: {{ ansible_facts.python_version }}"
## user add
@ -183,14 +174,7 @@
- user_test1.results is defined
- user_test1.results | length == 5
- name: validate changed results for testcase 1 (jinja >= 2.6)
assert:
that:
- user_test1.results | map(attribute='changed') | unique | list == [False]
- user_test1.results | map(attribute='state') | unique | list == ['present']
when: jinja2_version.stdout is version('2.6', '>=')
- name: validate changed results for testcase 1 (jinja < 2.6)
- name: validate changed results for testcase 1
assert:
that:
- "user_test1.results[0] is not changed"
@ -203,7 +187,6 @@
- "user_test1.results[2]['state'] == 'present'"
- "user_test1.results[3]['state'] == 'present'"
- "user_test1.results[4]['state'] == 'present'"
when: jinja2_version.stdout is version('2.6', '<')
## user remove

View file

@ -1,7 +1,11 @@
---
- name: Setup test fixture
shell: cat {{ role_path }}/fixtures/ansible-xml-beers.xml | sed 's/^[ ]*//g' > /tmp/ansible-xml-beers.xml
copy:
src: fixtures/ansible-xml-beers.xml
dest: /tmp/ansible-xml-beers.xml.orig
- name: Remove spaces from test fixture
shell: sed 's/^[ ]*//g' < /tmp/ansible-xml-beers.xml.orig > /tmp/ansible-xml-beers.xml
- name: Pretty print without modification
xml:

View file

@ -19,6 +19,7 @@
copy:
src: /tmp/ansible-xml-namespaced-beers.xml
dest: /tmp/ansible-xml-namespaced-beers-1.xml
remote_src: yes
- name: Set child elements again
xml:
@ -36,11 +37,13 @@
copy:
src: /tmp/ansible-xml-namespaced-beers.xml
dest: /tmp/ansible-xml-namespaced-beers-2.xml
remote_src: yes
- name: Compare to expected result
copy:
src: /tmp/ansible-xml-namespaced-beers-1.xml
dest: /tmp/ansible-xml-namespaced-beers-2.xml
remote_src: yes
check_mode: yes
diff: yes
register: comparison

View file

@ -1,4 +1,12 @@
---
- name: Copy expected results to remote
copy:
src: "results/{{ item }}"
dest: "/tmp/{{ item }}"
with_items:
- test-pretty-print.xml
- test-pretty-print-only.xml
# NOTE: Jinja2 templating eats trailing newlines
- name: Read from xmlstring (not using pretty_print)
xml:
@ -6,11 +14,10 @@
xpath: .
register: xmlresponse
- name: Compare to expected result
copy:
content: "{{ xmlresponse.xmlstring }}\n"
dest: '{{ role_path }}/results/test-pretty-print-only.xml'
dest: '/tmp/test-pretty-print-only.xml'
check_mode: yes
diff: yes
register: comparison
@ -33,7 +40,7 @@
- name: Compare to expected result
copy:
content: '{{ xmlresponse.xmlstring }}'
dest: '{{ role_path }}/results/test-pretty-print-only.xml'
dest: '/tmp/test-pretty-print-only.xml'
check_mode: yes
diff: yes
register: comparison
@ -60,7 +67,7 @@
- name: Compare to expected result
copy:
content: '{{ xmlresponse_modification.xmlstring }}'
dest: '{{ role_path }}/results/test-pretty-print.xml'
dest: '/tmp/test-pretty-print.xml'
check_mode: yes
diff: yes
register: comparison