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 shippable/posix/group2
context/controller context/target

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

@ -4,7 +4,7 @@
- name: prep for local facts tests - name: prep for local facts tests
block: block:
- name: set factdir var - 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 - name: create fact dir
file: path={{ fact_dir }} state=directory file: path={{ fact_dir }} state=directory

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

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

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

@ -4,7 +4,8 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule 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} results = {"data": data}

@ -3,7 +3,8 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule 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} 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: test_override:
register: result 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: assert:
that: 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 - name: Test that importing something from the module_utils in the env_vars works
test_env_override: test_env_override:

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

@ -2,13 +2,15 @@
set -eux 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 # 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. # 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_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 "$@" 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 # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # 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 # Verify correct default package manager for Fedora
# Validates: https://github.com/ansible/ansible/issues/34014 # Validates: https://github.com/ansible/ansible/issues/34014
- block: - block:

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

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

@ -3,4 +3,4 @@
set -ux set -ux
export ANSIBLE_BECOME_ALLOW_SAME_USER=1 export ANSIBLE_BECOME_ALLOW_SAME_USER=1
export ANSIBLE_ROLES_PATH=../ 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 # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # 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 - 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 - name: create our testing sub-directory
file: path="{{ output_dir_test }}" state=directory file: path="{{ remote_tmp_dir_test }}" state=directory
## ##
## raw ## raw
## ##
- name: touch a file - name: touch a file
raw: "touch {{output_dir_test | expanduser}}/test.txt" raw: "touch {{remote_tmp_dir_test | expanduser}}/test.txt"
register: raw_result0 register: raw_result0
- debug: var=raw_result0 - debug: var=raw_result0
- stat: - stat:
path: "{{output_dir_test | expanduser}}/test.txt" path: "{{remote_tmp_dir_test | expanduser}}/test.txt"
register: raw_result0_stat register: raw_result0_stat
- debug: var=raw_result0_stat - debug: var=raw_result0_stat
- name: ensure proper results - name: ensure proper results
@ -66,7 +66,7 @@
shell: which bash shell: which bash
register: bash_path register: bash_path
- name: run exmample non-posix command with bash - 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: args:
executable: "{{ bash_path.stdout }}" executable: "{{ bash_path.stdout }}"
register: raw_result2 register: raw_result2

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

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

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

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

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

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

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

@ -21,11 +21,6 @@
meta: end_host meta: end_host
when: ansible_distribution == 'Alpine' 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_user.yml
- import_tasks: test_create_system_user.yml - import_tasks: test_create_system_user.yml
- import_tasks: test_create_user_uid.yml - import_tasks: test_create_user_uid.yml

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

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

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

Loading…
Cancel
Save