The final `output_dir` pr (#76862)

pull/76866/head
Matt Martz 3 years ago committed by GitHub
parent bc5672d9ba
commit 3cf71ddf69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,2 +1,2 @@
shippable/posix/group2
context/controller
context/target

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

@ -4,7 +4,7 @@
- name: prep for local facts tests
block:
- name: set factdir var
set_fact: fact_dir={{output_dir}}/facts.d
set_fact: fact_dir={{remote_tmp_dir}}/facts.d
- name: create fact dir
file: path={{ fact_dir }} state=directory

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

@ -16,16 +16,16 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- set_fact: output_dir_test={{output_dir}}/test_find
- set_fact: remote_tmp_dir_test={{remote_tmp_dir}}/test_find
- name: make sure our testing sub-directory does not exist
file:
path: "{{ output_dir_test }}"
path: "{{ remote_tmp_dir_test }}"
state: absent
- name: create our testing sub-directory
file:
path: "{{ output_dir_test }}"
path: "{{ remote_tmp_dir_test }}"
state: directory
##
@ -34,7 +34,7 @@
- name: make some directories
file:
path: "{{ output_dir_test }}/{{ item }}"
path: "{{ remote_tmp_dir_test }}/{{ item }}"
state: directory
with_items:
- a/b/c/d
@ -42,7 +42,7 @@
- name: make some files
copy:
dest: "{{ output_dir_test }}/{{ item }}"
dest: "{{ remote_tmp_dir_test }}/{{ item }}"
content: 'data'
with_items:
- a/1.txt
@ -56,7 +56,7 @@
- name: find the directories
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
file_type: directory
recurse: yes
register: find_test0
@ -75,7 +75,7 @@
- name: find the xml and img files
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
file_type: file
patterns: "*.xml,*.img"
recurse: yes
@ -89,7 +89,7 @@
- name: find the xml file
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
patterns: "*.xml"
recurse: yes
register: find_test2
@ -103,7 +103,7 @@
- name: find the xml file with empty excludes
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
patterns: "*.xml"
recurse: yes
excludes: []
@ -119,7 +119,7 @@
- name: Copy some files into the test dir
copy:
src: "{{ item }}"
dest: "{{ output_dir_test }}/{{ item }}"
dest: "{{ remote_tmp_dir_test }}/{{ item }}"
mode: 0644
with_items:
- a.txt
@ -127,7 +127,7 @@
- name: Ensure '$' only matches the true end of the file with read_whole_file, not a line
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
patterns: "*.txt"
contains: "KO$"
read_whole_file: true
@ -141,7 +141,7 @@
- name: Match the end of the file successfully
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
patterns: "*.txt"
contains: "OK$"
read_whole_file: true
@ -155,7 +155,7 @@
- name: When read_whole_file=False, $ should match an individual line
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
patterns: "*.txt"
contains: ".*KO$"
read_whole_file: false
@ -169,7 +169,7 @@
- name: When read_whole_file=True, match across line boundaries
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
patterns: "*.txt"
contains: "has\na few"
read_whole_file: true
@ -183,7 +183,7 @@
- name: When read_whole_file=False, do not match across line boundaries
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
patterns: "*.txt"
contains: "has\na few"
read_whole_file: false
@ -214,7 +214,7 @@
block:
- name: Get all files/directories in the path
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
recurse: yes
file_type: any
register: total_contents
@ -226,7 +226,7 @@
- name: Get files and directories with depth
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
recurse: yes
file_type: any
depth: 2
@ -241,7 +241,7 @@
- name: Find files with depth
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
depth: 2
recurse: yes
register: files_with_depth
@ -254,7 +254,7 @@
- files_with_depth.examined == 12
- name: exclude with regex
find:
paths: "{{ output_dir_test }}"
paths: "{{ remote_tmp_dir_test }}"
recurse: yes
use_regex: true
exclude: .*\.ogg
@ -266,32 +266,32 @@
- name: assert we skipped the ogg file
assert:
that:
- '"{{ output_dir_test }}/e/f/g/h/8.ogg" not in find_test3_list'
- '"{{ remote_tmp_dir_test }}/e/f/g/h/8.ogg" not in find_test3_list'
- name: create our age/size testing sub-directory
file:
path: "{{ output_dir_test }}/astest"
path: "{{ remote_tmp_dir_test }}/astest"
state: directory
- name: create test file with old timestamps
file:
path: "{{ output_dir_test }}/astest/old.txt"
path: "{{ remote_tmp_dir_test }}/astest/old.txt"
state: touch
modification_time: "202001011200.0"
- name: create test file with current timestamps
file:
path: "{{ output_dir_test }}/astest/new.txt"
path: "{{ remote_tmp_dir_test }}/astest/new.txt"
state: touch
- name: create hidden test file with current timestamps
file:
path: "{{ output_dir_test }}/astest/.hidden.txt"
path: "{{ remote_tmp_dir_test }}/astest/.hidden.txt"
state: touch
- name: find files older than 1 week
find:
path: "{{ output_dir_test }}/astest"
path: "{{ remote_tmp_dir_test }}/astest"
age: 1w
hidden: true
register: result
@ -303,11 +303,11 @@
assert:
that:
- result.matched == 1
- '"{{ output_dir_test }}/astest/old.txt" in astest_list'
- '"{{ remote_tmp_dir_test }}/astest/old.txt" in astest_list'
- name: find files newer than 1 week
find:
path: "{{ output_dir_test }}/astest"
path: "{{ remote_tmp_dir_test }}/astest"
age: -1w
register: result
@ -318,14 +318,14 @@
assert:
that:
- result.matched == 1
- '"{{ output_dir_test }}/astest/new.txt" in astest_list'
- '"{{ remote_tmp_dir_test }}/astest/new.txt" in astest_list'
- name: add some content to the new file
shell: "echo hello world > {{ output_dir_test }}/astest/new.txt"
shell: "echo hello world > {{ remote_tmp_dir_test }}/astest/new.txt"
- name: find files with MORE than 5 bytes, also get checksums
find:
path: "{{ output_dir_test }}/astest"
path: "{{ remote_tmp_dir_test }}/astest"
size: 5
hidden: true
get_checksum: true
@ -338,12 +338,12 @@
assert:
that:
- result.matched == 1
- '"{{ output_dir_test }}/astest/new.txt" in astest_list'
- '"{{ remote_tmp_dir_test }}/astest/new.txt" in astest_list'
- '"checksum" in result.files[0]'
- name: find ANY item with LESS than 5 bytes, also get checksums
find:
path: "{{ output_dir_test }}/astest"
path: "{{ remote_tmp_dir_test }}/astest"
size: -5
hidden: true
get_checksum: true
@ -357,6 +357,6 @@
assert:
that:
- result.matched == 2
- '"{{ output_dir_test }}/astest/old.txt" in astest_list'
- '"{{ output_dir_test }}/astest/.hidden.txt" in astest_list'
- '"{{ remote_tmp_dir_test }}/astest/old.txt" in astest_list'
- '"{{ remote_tmp_dir_test }}/astest/.hidden.txt" in astest_list'
- '"checksum" in result.files[0]'

@ -1,4 +1,5 @@
shippable/posix/group3
needs/root
needs/target/setup_nobody
needs/target/setup_remote_tmp_dir
context/target

@ -4,7 +4,8 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.facts import data
# overridden
from ansible.module_utils.ansible_release import data
results = {"data": data}

@ -3,7 +3,8 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.facts import data
# overridden
from ansible.module_utils.ansible_release import data
results = {"data": data}

@ -0,0 +1,4 @@
# This file overrides the builtin ansible.module_utils.ansible_release file
# to test that it can be overridden. Previously this was facts.py but caused issues
# with dependencies that may need to execute a module that makes use of facts
data = 'overridden ansible_release.py'

@ -33,10 +33,10 @@
test_override:
register: result
- name: Make sure the we used the local facts.py, not the one shipped with ansible
- name: Make sure the we used the local ansible_release.py, not the one shipped with ansible
assert:
that:
- 'result["data"] == "overridden facts.py"'
- 'result["data"] == "overridden ansible_release.py"'
- name: Test that importing something from the module_utils in the env_vars works
test_env_override:

@ -33,10 +33,10 @@
test_override:
register: result
- name: Make sure the we used the local facts.py, not the one shipped with ansible
- name: Make sure the we used the local ansible_release.py, not the one shipped with ansible
assert:
that:
- result["data"] == "overridden facts.py"
- result["data"] == "overridden ansible_release.py"
- name: Test that importing a module that only exists inside of a submodule does not work
test_failure:
@ -61,13 +61,16 @@
- result.deprecations[-1].version == '9.99'
- block:
- import_role:
name: setup_remote_tmp_dir
- name: Get a string with a \0 in it
command: echo -e 'hi\0foo'
register: string_with_null
- name: Use the null string as a module parameter
lineinfile:
path: "{{ output_dir }}/nulltest"
path: "{{ remote_tmp_dir }}/nulltest"
line: "{{ string_with_null.stdout }}"
create: yes
ignore_errors: yes
@ -75,7 +78,7 @@
- name: See if the file exists
stat:
path: "{{ output_dir }}/nulltest"
path: "{{ remote_tmp_dir }}/nulltest"
register: nullstat
- assert:
@ -94,7 +97,7 @@
- nullstat.stat.exists == nulltest is successful
always:
- file:
path: "{{ output_dir }}/nulltest"
path: "{{ remote_tmp_dir }}/nulltest"
state: absent
- name: Test that date and datetime in module output works

@ -2,13 +2,15 @@
set -eux
ANSIBLE_ROLES_PATH=../ ansible-playbook module_utils_basic_setcwd.yml -i ../../inventory "$@"
export ANSIBLE_ROLES_PATH=../
ansible-playbook module_utils_basic_setcwd.yml -i ../../inventory "$@"
# Keep the -vvvvv here. This acts as a test for testing that higher verbosity
# doesn't traceback with unicode in the custom module_utils directory path.
ansible-playbook module_utils_vvvvv.yml -i ../../inventory -vvvvv "$@"
ansible-playbook module_utils_test.yml -i ../../inventory -e output_dir="$OUTPUT_DIR" -v "$@"
ansible-playbook module_utils_test.yml -i ../../inventory -v "$@"
ANSIBLE_MODULE_UTILS=other_mu_dir ansible-playbook module_utils_envvar.yml -i ../../inventory -v "$@"

@ -16,14 +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/>.
- set_fact: output_dir_test={{output_dir}}/at
- name: make sure our testing sub-directory does not exist
file: path="{{ output_dir_test }}" state=absent
- name: create our testing sub-directory
file: path="{{ output_dir_test }}" state=directory
# Verify correct default package manager for Fedora
# Validates: https://github.com/ansible/ansible/issues/34014
- block:

@ -1 +1,2 @@
shippable/posix/group1
needs/target/setup_remote_tmp_dir

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

@ -3,4 +3,4 @@
set -ux
export ANSIBLE_BECOME_ALLOW_SAME_USER=1
export ANSIBLE_ROLES_PATH=../
ansible-playbook -i ../../inventory runme.yml -e "output_dir=${OUTPUT_DIR}" -v "$@"
ansible-playbook -i ../../inventory runme.yml -v "$@"

@ -16,24 +16,24 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- set_fact: output_dir_test={{output_dir}}/test_command_raw
- set_fact: remote_tmp_dir_test={{remote_tmp_dir}}/test_command_raw
- name: make sure our testing sub-directory does not exist
file: path="{{ output_dir_test }}" state=absent
file: path="{{ remote_tmp_dir_test }}" state=absent
- name: create our testing sub-directory
file: path="{{ output_dir_test }}" state=directory
file: path="{{ remote_tmp_dir_test }}" state=directory
##
## raw
##
- name: touch a file
raw: "touch {{output_dir_test | expanduser}}/test.txt"
raw: "touch {{remote_tmp_dir_test | expanduser}}/test.txt"
register: raw_result0
- debug: var=raw_result0
- stat:
path: "{{output_dir_test | expanduser}}/test.txt"
path: "{{remote_tmp_dir_test | expanduser}}/test.txt"
register: raw_result0_stat
- debug: var=raw_result0_stat
- name: ensure proper results
@ -66,7 +66,7 @@
shell: which bash
register: bash_path
- name: run exmample non-posix command with bash
raw: "echo 'foobar' > {{output_dir_test | expanduser}}/test.txt ; cat < {{output_dir_test | expanduser}}/test.txt"
raw: "echo 'foobar' > {{remote_tmp_dir_test | expanduser}}/test.txt ; cat < {{remote_tmp_dir_test | expanduser}}/test.txt"
args:
executable: "{{ bash_path.stdout }}"
register: raw_result2

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

@ -1,11 +1,11 @@
# setup
- set_fact: output_dir_test={{output_dir}}/test_replace
- set_fact: remote_tmp_dir_test={{remote_tmp_dir}}/test_replace
- name: make sure our testing sub-directory does not exist
file: path="{{ output_dir_test }}" state=absent
file: path="{{ remote_tmp_dir_test }}" state=absent
- name: create our testing sub-directory
file: path="{{ output_dir_test }}" state=directory
file: path="{{ remote_tmp_dir_test }}" state=directory
# tests
- name: create test files
@ -15,19 +15,19 @@
We promptly judged antique ivory buckles for the next prize.
Jinxed wizards pluck ivy from the big quilt.
Jaded zombies acted quaintly but kept driving their oxen forward.
dest: "{{ output_dir_test }}/pangrams.{{ item }}.txt"
dest: "{{ remote_tmp_dir_test }}/pangrams.{{ item }}.txt"
with_sequence: start=0 end=6 format=%02x #increment as needed
## test `before` option
- name: remove all spaces before "quilt"
replace:
path: "{{ output_dir_test }}/pangrams.00.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.00.txt"
before: 'quilt'
regexp: ' '
register: replace_test0
- command: "cat {{ output_dir_test }}/pangrams.00.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.00.txt"
register: replace_cat0
- name: validate before assertions
@ -42,12 +42,12 @@
## test `after` option
- name: remove all spaces after "promptly"
replace:
path: "{{ output_dir_test }}/pangrams.01.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.01.txt"
after: 'promptly'
regexp: ' '
register: replace_test1
- command: "cat {{ output_dir_test }}/pangrams.01.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.01.txt"
register: replace_cat1
- name: validate after assertions
@ -62,7 +62,7 @@
## test combined `before` and `after` options
- name: before "promptly" but after "quilt", replace every "e" with a "3"
replace:
path: "{{ output_dir_test }}/pangrams.02.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.02.txt"
before: 'promptly'
after: 'quilt'
regexp: 'e'
@ -78,14 +78,14 @@
- name: before "quilt" but after "promptly", replace every "e" with a "3"
replace:
path: "{{ output_dir_test }}/pangrams.03.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.03.txt"
before: 'quilt'
after: 'promptly'
regexp: 'e'
replace: '3'
register: replace_test3
- command: "cat {{ output_dir_test }}/pangrams.03.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.03.txt"
register: replace_cat3
- name: validate before+after assertions
@ -99,22 +99,22 @@
## test ^$ behavior in MULTILINE, and . behavior in absense of DOTALL
- name: quote everything between bof and eof
replace:
path: "{{ output_dir_test }}/pangrams.04.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.04.txt"
regexp: ^([\S\s]+)$
replace: '"\1"'
register: replace_test4_0
- command: "cat {{ output_dir_test }}/pangrams.04.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.04.txt"
register: replace_cat4_0
- name: quote everything between bol and eol
replace:
path: "{{ output_dir_test }}/pangrams.04.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.04.txt"
regexp: ^(.+)$
replace: '"\1"'
register: replace_test4_1
- command: "cat {{ output_dir_test }}/pangrams.04.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.04.txt"
register: replace_cat4_1
- name: validate before+after assertions
@ -132,29 +132,29 @@
## test \b escaping in short and long form
- name: short form with unescaped word boundaries
replace: path="{{ output_dir_test }}/pangrams.05.txt" regexp='\b(.+)\b' replace='"\1"'
replace: path="{{ remote_tmp_dir_test }}/pangrams.05.txt" regexp='\b(.+)\b' replace='"\1"'
register: replace_test5_0
- name: short form with escaped word boundaries
replace: path="{{ output_dir_test }}/pangrams.05.txt" regexp='\\b(.+)\\b' replace='"\1"'
replace: path="{{ remote_tmp_dir_test }}/pangrams.05.txt" regexp='\\b(.+)\\b' replace='"\1"'
register: replace_test5_1
- command: "cat {{ output_dir_test }}/pangrams.05.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.05.txt"
register: replace_cat5_1
- name: long form with unescaped word boundaries
replace:
path: "{{ output_dir_test }}/pangrams.05.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.05.txt"
regexp: '\b(.+)\b'
replace: '"\1"'
register: replace_test5_2
- command: "cat {{ output_dir_test }}/pangrams.05.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.05.txt"
register: replace_cat5_2
- name: long form with escaped word boundaries
replace:
path: "{{ output_dir_test }}/pangrams.05.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.05.txt"
regexp: '\\b(.+)\\b'
replace: '"\1"'
register: replace_test5_3
@ -175,13 +175,13 @@
## test backup behaviors
- name: replacement with backup
replace:
path: "{{ output_dir_test }}/pangrams.06.txt"
path: "{{ remote_tmp_dir_test }}/pangrams.06.txt"
regexp: ^(.+)$
replace: '"\1"'
backup: true
register: replace_test6
- command: "cat {{ output_dir_test }}/pangrams.06.txt"
- command: "cat {{ remote_tmp_dir_test }}/pangrams.06.txt"
register: replace_cat6_0
- command: "cat {{ replace_test6.backup_file }}"
@ -199,14 +199,14 @@
## test filesystem failures
- name: fail on directory
replace:
path: "{{ output_dir_test }}"
path: "{{ remote_tmp_dir_test }}"
regexp: ^(.+)$
register: replace_test7_1
ignore_errors: true
- name: fail on missing file
replace:
path: "{{ output_dir_test }}/missing_file.txt"
path: "{{ remote_tmp_dir_test }}/missing_file.txt"
regexp: ^(.+)$
register: replace_test7_2
ignore_errors: true
@ -241,18 +241,18 @@
127.0.0.1
127.0.1.1
# end of group
dest: "{{ output_dir_test }}/addresses.txt"
dest: "{{ remote_tmp_dir_test }}/addresses.txt"
- name: subsection madness
replace:
path: "{{ output_dir_test }}/addresses.txt"
path: "{{ remote_tmp_dir_test }}/addresses.txt"
after: '# start of group'
before: '# end of group'
regexp: '0'
replace: '9'
register: replace_test8
- command: "cat {{ output_dir_test }}/addresses.txt"
- command: "cat {{ remote_tmp_dir_test }}/addresses.txt"
register: replace_cat8
- name: validate before+after assertions

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

@ -13,7 +13,7 @@
- name: Save gpg keys to a file
copy:
content: "{{ pubkeys['stdout'] }}\n"
dest: '{{ output_dir }}/pubkeys'
dest: '{{ remote_tmp_dir }}/pubkeys'
mode: 0600
#
@ -183,7 +183,7 @@
shell: "rpm -q gpg-pubkey | xargs rpm -e"
- name: Restore the gpg keys normally installed on the system
command: 'rpm --import {{ output_dir }}/pubkeys'
command: 'rpm --import {{ remote_tmp_dir }}/pubkeys'
- name: Retrieve a list of gpg keys are installed for package checking
shell: 'rpm -q gpg-pubkey | sort'

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

@ -21,16 +21,16 @@
##
- set_fact:
output_dir_test: "{{ output_dir }}/test_script"
remote_tmp_dir_test: "{{ remote_tmp_dir }}/test_script"
- name: make sure our testing sub-directory does not exist
file:
path: "{{ output_dir_test }}"
path: "{{ remote_tmp_dir_test }}"
state: absent
- name: create our testing sub-directory
file:
path: "{{ output_dir_test }}"
path: "{{ remote_tmp_dir_test }}"
state: directory
##
@ -76,24 +76,24 @@
# creates
- name: verify that afile.txt is absent
file:
path: "{{ output_dir_test }}/afile.txt"
path: "{{ remote_tmp_dir_test }}/afile.txt"
state: absent
- name: create afile.txt with create_afile.sh via command
script: create_afile.sh {{ output_dir_test | expanduser }}/afile.txt
script: create_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile.txt
args:
creates: "{{ output_dir_test | expanduser }}/afile.txt"
creates: "{{ remote_tmp_dir_test | expanduser }}/afile.txt"
register: _create_test1
- name: Check state of created file
stat:
path: "{{ output_dir_test | expanduser }}/afile.txt"
path: "{{ remote_tmp_dir_test | expanduser }}/afile.txt"
register: _create_stat1
- name: Run create_afile.sh again to ensure it is skipped
script: create_afile.sh {{ output_dir_test | expanduser }}/afile.txt
script: create_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile.txt
args:
creates: "{{ output_dir_test | expanduser }}/afile.txt"
creates: "{{ remote_tmp_dir_test | expanduser }}/afile.txt"
register: _create_test2
- name: Assert that script report a change, file was created, second run was skipped
@ -107,24 +107,24 @@
# removes
- name: verify that afile.txt is present
file:
path: "{{ output_dir_test }}/afile.txt"
path: "{{ remote_tmp_dir_test }}/afile.txt"
state: file
- name: remove afile.txt with remote_afile.sh via command
script: remove_afile.sh {{ output_dir_test | expanduser }}/afile.txt
script: remove_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile.txt
args:
removes: "{{ output_dir_test | expanduser }}/afile.txt"
removes: "{{ remote_tmp_dir_test | expanduser }}/afile.txt"
register: _remove_test1
- name: Check state of removed file
stat:
path: "{{ output_dir_test | expanduser }}/afile.txt"
path: "{{ remote_tmp_dir_test | expanduser }}/afile.txt"
register: _remove_stat1
- name: Run remote_afile.sh again to enure it is skipped
script: remove_afile.sh {{ output_dir_test | expanduser }}/afile.txt
script: remove_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile.txt
args:
removes: "{{ output_dir_test | expanduser }}/afile.txt"
removes: "{{ remote_tmp_dir_test | expanduser }}/afile.txt"
register: _remove_test2
- name: Assert that script report a change, file was removed, second run was skipped
@ -138,7 +138,7 @@
# async
- name: verify that afile.txt is absent
file:
path: "{{ output_dir_test }}/afile.txt"
path: "{{ remote_tmp_dir_test }}/afile.txt"
state: absent
- name: test task failure with async param
@ -156,7 +156,7 @@
# check mode
- name: Run script to create a file in check mode
script: create_afile.sh {{ output_dir_test | expanduser }}/afile2.txt
script: create_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile2.txt
check_mode: yes
register: _check_mode_test
@ -166,7 +166,7 @@
- name: Get state of file created by script
stat:
path: "{{ output_dir_test | expanduser }}/afile2.txt"
path: "{{ remote_tmp_dir_test | expanduser }}/afile2.txt"
register: _afile_stat
- debug:
@ -181,12 +181,12 @@
- not _afile_stat.stat.exists
- name: Run script to create a file
script: create_afile.sh {{ output_dir_test | expanduser }}/afile2.txt
script: create_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile2.txt
- name: Run script to create a file in check mode with 'creates' argument
script: create_afile.sh {{ output_dir_test | expanduser }}/afile2.txt
script: create_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile2.txt
args:
creates: "{{ output_dir_test | expanduser }}/afile2.txt"
creates: "{{ remote_tmp_dir_test | expanduser }}/afile2.txt"
register: _check_mode_test2
check_mode: yes
@ -198,17 +198,17 @@
assert:
that:
- _check_mode_test2 is skipped
- '_check_mode_test2.msg == "{{ output_dir_test | expanduser }}/afile2.txt exists, matching creates option"'
- '_check_mode_test2.msg == "{{ remote_tmp_dir_test | expanduser }}/afile2.txt exists, matching creates option"'
- name: Remove afile2.txt
file:
path: "{{ output_dir_test | expanduser }}/afile2.txt"
path: "{{ remote_tmp_dir_test | expanduser }}/afile2.txt"
state: absent
- name: Run script to remove a file in check mode with 'removes' argument
script: remove_afile.sh {{ output_dir_test | expanduser }}/afile2.txt
script: remove_afile.sh {{ remote_tmp_dir_test | expanduser }}/afile2.txt
args:
removes: "{{ output_dir_test | expanduser }}/afile2.txt"
removes: "{{ remote_tmp_dir_test | expanduser }}/afile2.txt"
register: _check_mode_test3
check_mode: yes
@ -220,7 +220,7 @@
assert:
that:
- _check_mode_test3 is skipped
- '_check_mode_test3.msg == "{{ output_dir_test | expanduser }}/afile2.txt does not exist, matching removes option"'
- '_check_mode_test3.msg == "{{ remote_tmp_dir_test | expanduser }}/afile2.txt does not exist, matching removes option"'
# executable

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

@ -19,11 +19,11 @@
- name: Create a UTF-8 file to test with
copy:
content: 'We are at the café'
dest: '{{ output_dir }}/foo.txt'
dest: '{{ remote_tmp_dir }}/foo.txt'
- name: test slurping an existing file
slurp:
src: '{{ output_dir }}/foo.txt'
src: '{{ remote_tmp_dir }}/foo.txt'
register: slurp_existing
- name: check slurp existing result
@ -38,11 +38,11 @@
- name: Create a binary file to test with
copy:
src: bar.bin
dest: '{{ output_dir }}/bar.bin'
dest: '{{ remote_tmp_dir }}/bar.bin'
- name: test slurping a binary file
slurp:
path: '{{ output_dir }}/bar.bin'
path: '{{ remote_tmp_dir }}/bar.bin'
register: slurp_binary
no_log: true

@ -1,17 +1,17 @@
- name: test slurping a non-existent file
slurp:
src: '{{ output_dir }}/i_do_not_exist'
src: '{{ remote_tmp_dir }}/i_do_not_exist'
register: slurp_missing
ignore_errors: yes
- name: Create a directory to test with
file:
path: '{{ output_dir }}/baz/'
path: '{{ remote_tmp_dir }}/baz/'
state: directory
- name: test slurping a directory
slurp:
src: '{{ output_dir }}/baz'
src: '{{ remote_tmp_dir }}/baz'
register: slurp_dir
ignore_errors: yes
@ -27,13 +27,13 @@
- name: create unreadable file
copy:
content: "Hello, World!"
dest: "{{ output_dir }}/qux.txt"
dest: "{{ remote_tmp_dir }}/qux.txt"
mode: '0600'
owner: root
- name: test slurp unreadable file
slurp:
src: "{{ output_dir }}/qux.txt"
src: "{{ remote_tmp_dir }}/qux.txt"
register: slurp_unreadable_file
become: yes
become_user: "{{ become_test_user }}"
@ -42,14 +42,14 @@
- name: create unreadable directory
file:
path: "{{ output_dir }}/test_data"
path: "{{ remote_tmp_dir }}/test_data"
state: directory
mode: '0700'
owner: root
- name: test slurp unreadable directory
slurp:
src: "{{ output_dir }}/test_data"
src: "{{ remote_tmp_dir }}/test_data"
register: slurp_unreadable_dir
become: yes
become_user: "{{ become_test_user }}"
@ -58,7 +58,7 @@
- name: Try to access file as directory
slurp:
src: "{{ output_dir }}/qux.txt/somefile"
src: "{{ remote_tmp_dir }}/qux.txt/somefile"
ignore_errors: yes
register: slurp_path_file_as_dir

@ -21,11 +21,6 @@
meta: end_host
when: ansible_distribution == 'Alpine'
- name: ensure output directory exists
file:
dest: "{{ output_dir }}"
state: directory
- import_tasks: test_create_user.yml
- import_tasks: test_create_system_user.yml
- import_tasks: test_create_user_uid.yml

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

@ -18,21 +18,21 @@
- name: setup webserver
copy:
src: "testserver.py"
dest: "{{ output_dir }}/testserver.py"
dest: "{{ remote_tmp_dir }}/testserver.py"
- name: setup a path
file:
path: "{{ output_dir }}/wait_for_file"
path: "{{ remote_tmp_dir }}/wait_for_file"
state: touch
- name: setup remove a file after 3s
shell: sleep 3 && rm {{ output_dir }}/wait_for_file
shell: sleep 3 && rm {{ remote_tmp_dir }}/wait_for_file
async: 20
poll: 0
- name: test for absent path
wait_for:
path: "{{ output_dir }}/wait_for_file"
path: "{{ remote_tmp_dir }}/wait_for_file"
state: absent
timeout: 20
register: waitfor
@ -40,36 +40,36 @@
assert:
that:
- waitfor is successful
- waitfor.path == "{{ output_dir | expanduser }}/wait_for_file"
- waitfor.path == "{{ remote_tmp_dir | expanduser }}/wait_for_file"
- waitfor.elapsed >= 2
- waitfor.elapsed <= 15
- name: setup create a file after 3s
shell: sleep 3 && touch {{ output_dir }}/wait_for_file
shell: sleep 3 && touch {{ remote_tmp_dir }}/wait_for_file
async: 20
poll: 0
- name: test for present path
wait_for:
path: "{{ output_dir }}/wait_for_file"
path: "{{ remote_tmp_dir }}/wait_for_file"
timeout: 5
register: waitfor
- name: verify test for absent path
assert:
that:
- waitfor is successful
- waitfor.path == "{{ output_dir | expanduser }}/wait_for_file"
- waitfor.path == "{{ remote_tmp_dir | expanduser }}/wait_for_file"
- waitfor.elapsed >= 2
- waitfor.elapsed <= 15
- name: setup write keyword to file after 3s
shell: sleep 3 && echo completed > {{output_dir}}/wait_for_keyword
shell: sleep 3 && echo completed > {{remote_tmp_dir}}/wait_for_keyword
async: 20
poll: 0
- name: test wait for keyword in file
wait_for:
path: "{{output_dir}}/wait_for_keyword"
path: "{{remote_tmp_dir}}/wait_for_keyword"
search_regex: completed
timeout: 5
register: waitfor
@ -83,13 +83,13 @@
- waitfor.elapsed <= 15
- name: setup write keyword to file after 3s
shell: sleep 3 && echo "completed data 123" > {{output_dir}}/wait_for_keyword
shell: sleep 3 && echo "completed data 123" > {{remote_tmp_dir}}/wait_for_keyword
async: 20
poll: 0
- name: test wait for keyword in file with match groups
wait_for:
path: "{{output_dir}}/wait_for_keyword"
path: "{{remote_tmp_dir}}/wait_for_keyword"
search_regex: completed (?P<foo>\w+) ([0-9]+)
timeout: 5
register: waitfor
@ -132,7 +132,7 @@
- "waitfor.msg == 'fail with custom message'"
- name: setup start SimpleHTTPServer
shell: sleep 3 && cd {{ files_dir }} && {{ ansible_python.executable }} {{ output_dir}}/testserver.py {{ http_port }}
shell: sleep 3 && cd {{ files_dir }} && {{ ansible_python.executable }} {{ remote_tmp_dir}}/testserver.py {{ http_port }}
async: 120 # this test set can take ~1m to run on FreeBSD (via Shippable)
poll: 0
@ -156,10 +156,10 @@
- name: Copy zombie.py
copy:
src: zombie.py
dest: "{{ output_dir }}"
dest: "{{ remote_tmp_dir }}"
- name: Create zombie process
shell: "{{ ansible_python.executable }} {{ output_dir }}/zombie"
shell: "{{ ansible_python.executable }} {{ remote_tmp_dir }}/zombie"
async: 90
poll: 0

@ -1,4 +1,4 @@
---
http_port: 15261
files_dir: '{{ output_dir|expanduser }}/files'
checkout_dir: '{{ output_dir }}/git'
files_dir: '{{ remote_tmp_dir|expanduser }}/files'
checkout_dir: '{{ remote_tmp_dir }}/git'

Loading…
Cancel
Save