group2 - switch to setup_remote_tmp_dir instead of using output_dir (#76853)

* group2 - switch to setup_remote_tmp_dir instead of using output_dir

* output_file needs to be in the tmp dir

* Use comparison that should work with macos

* remove unused dep
pull/76858/head
Matt Martz 4 years ago committed by GitHub
parent 73dd2c3607
commit cad200406a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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}}/apt_key
- 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
- import_tasks: 'apt_key.yml' - import_tasks: 'apt_key.yml'
when: ansible_distribution in ('Ubuntu', 'Debian') when: ansible_distribution in ('Ubuntu', 'Debian')

@ -18,3 +18,4 @@
dependencies: dependencies:
- prepare_tests - prepare_tests
- setup_remote_tmp_dir

@ -16,21 +16,12 @@
# 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/>.
- name: create a new directory for file source
file: dest="{{output_dir}}/src" state=directory
register: result
- name: assert the directory was created
assert:
that:
- "result.state == 'directory'"
- name: copy the files to a new directory - name: copy the files to a new directory
copy: src="./" dest="{{output_dir}}/src" copy: src="./" dest="{{remote_tmp_dir}}/src"
register: result register: result
- name: create unicode file for test - name: create unicode file for test
shell: echo "π" > {{ output_dir }}/src/ßΩ.txt shell: echo "π" > {{ remote_tmp_dir }}/src/ßΩ.txt
register: result register: result
- name: assert that the new file was created - name: assert that the new file was created
@ -39,7 +30,7 @@
- "result.changed == true" - "result.changed == true"
- name: test assemble with all fragments - name: test assemble with all fragments
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled1" assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled1"
register: result register: result
- name: assert the fragments were assembled - name: assert the fragments were assembled
@ -50,7 +41,7 @@
- "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'" - "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
- name: test assemble with all fragments - name: test assemble with all fragments
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled1" assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled1"
register: result register: result
- name: assert that the same assemble made no changes - name: assert that the same assemble made no changes
@ -61,7 +52,7 @@
- "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'" - "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
- name: test assemble with all fragments and decrypt=True - name: test assemble with all fragments and decrypt=True
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled2" decrypt=yes assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled2" decrypt=yes
register: result register: result
- name: assert the fragments were assembled with decrypt=True - name: assert the fragments were assembled with decrypt=True
@ -72,7 +63,7 @@
- "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'" - "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
- name: test assemble with all fragments and decrypt=True - name: test assemble with all fragments and decrypt=True
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled2" decrypt=yes assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled2" decrypt=yes
register: result register: result
- name: assert that the same assemble made no changes with decrypt=True - name: assert that the same assemble made no changes with decrypt=True
@ -83,7 +74,7 @@
- "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'" - "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
- name: test assemble with fragments matching a regex - name: test assemble with fragments matching a regex
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled3" regexp="^fragment[1-3]$" assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled3" regexp="^fragment[1-3]$"
register: result register: result
- name: assert the fragments were assembled with a regex - name: assert the fragments were assembled with a regex
@ -93,7 +84,7 @@
- "result.checksum == 'edfe2d7487ef8f5ebc0f1c4dc57ba7b70a7b8e2b'" - "result.checksum == 'edfe2d7487ef8f5ebc0f1c4dc57ba7b70a7b8e2b'"
- name: test assemble with fragments matching a regex and decrypt=True - name: test assemble with fragments matching a regex and decrypt=True
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled4" regexp="^fragment[1-3]$" decrypt=yes assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled4" regexp="^fragment[1-3]$" decrypt=yes
register: result register: result
- name: assert the fragments were assembled with a regex and decrypt=True - name: assert the fragments were assembled with a regex and decrypt=True
@ -103,7 +94,7 @@
- "result.checksum == 'edfe2d7487ef8f5ebc0f1c4dc57ba7b70a7b8e2b'" - "result.checksum == 'edfe2d7487ef8f5ebc0f1c4dc57ba7b70a7b8e2b'"
- name: test assemble with a delimiter - name: test assemble with a delimiter
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled5" delimiter="#--- delimiter ---#" assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled5" delimiter="#--- delimiter ---#"
register: result register: result
- name: assert the fragments were assembled with a delimiter - name: assert the fragments were assembled with a delimiter
@ -113,7 +104,7 @@
- "result.checksum == 'd986cefb82e34e4cf14d33a3cda132ff45aa2980'" - "result.checksum == 'd986cefb82e34e4cf14d33a3cda132ff45aa2980'"
- name: test assemble with a delimiter and decrypt=True - name: test assemble with a delimiter and decrypt=True
assemble: src="{{output_dir}}/src" dest="{{output_dir}}/assembled6" delimiter="#--- delimiter ---#" decrypt=yes assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled6" delimiter="#--- delimiter ---#" decrypt=yes
register: result register: result
- name: assert the fragments were assembled with a delimiter and decrypt=True - name: assert the fragments were assembled with a delimiter and decrypt=True
@ -123,7 +114,7 @@
- "result.checksum == 'd986cefb82e34e4cf14d33a3cda132ff45aa2980'" - "result.checksum == 'd986cefb82e34e4cf14d33a3cda132ff45aa2980'"
- name: test assemble with remote_src=False - name: test assemble with remote_src=False
assemble: src="./" dest="{{output_dir}}/assembled7" remote_src=no assemble: src="./" dest="{{remote_tmp_dir}}/assembled7" remote_src=no
register: result register: result
- name: assert the fragments were assembled without remote - name: assert the fragments were assembled without remote
@ -133,7 +124,7 @@
- "result.checksum == '048a1bd1951aa5ccc427eeb4ca19aee45e9c68b3'" - "result.checksum == '048a1bd1951aa5ccc427eeb4ca19aee45e9c68b3'"
- name: test assemble with remote_src=False and decrypt=True - name: test assemble with remote_src=False and decrypt=True
assemble: src="./" dest="{{output_dir}}/assembled8" remote_src=no decrypt=yes assemble: src="./" dest="{{remote_tmp_dir}}/assembled8" remote_src=no decrypt=yes
register: result register: result
- name: assert the fragments were assembled without remote and decrypt=True - name: assert the fragments were assembled without remote and decrypt=True
@ -143,7 +134,7 @@
- "result.checksum == '048a1bd1951aa5ccc427eeb4ca19aee45e9c68b3'" - "result.checksum == '048a1bd1951aa5ccc427eeb4ca19aee45e9c68b3'"
- name: test assemble with remote_src=False and a delimiter - name: test assemble with remote_src=False and a delimiter
assemble: src="./" dest="{{output_dir}}/assembled9" remote_src=no delimiter="#--- delimiter ---#" assemble: src="./" dest="{{remote_tmp_dir}}/assembled9" remote_src=no delimiter="#--- delimiter ---#"
register: result register: result
- name: assert the fragments were assembled without remote - name: assert the fragments were assembled without remote
@ -153,7 +144,7 @@
- "result.checksum == '505359f48c65b3904127cf62b912991d4da7ed6d'" - "result.checksum == '505359f48c65b3904127cf62b912991d4da7ed6d'"
- name: test assemble with remote_src=False and a delimiter and decrypt=True - name: test assemble with remote_src=False and a delimiter and decrypt=True
assemble: src="./" dest="{{output_dir}}/assembled10" remote_src=no delimiter="#--- delimiter ---#" decrypt=yes assemble: src="./" dest="{{remote_tmp_dir}}/assembled10" remote_src=no delimiter="#--- delimiter ---#" decrypt=yes
register: result register: result
- name: assert the fragments were assembled without remote - name: assert the fragments were assembled without remote

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

@ -12,37 +12,37 @@
- name: get checksums that we expect later files to have - name: get checksums that we expect later files to have
copy: copy:
src: from_playbook src: from_playbook
dest: "{{ output_dir }}" dest: "{{ remote_tmp_dir }}"
- copy: - copy:
src: b64_utf8 src: b64_utf8
dest: "{{ output_dir }}" dest: "{{ remote_tmp_dir }}"
- copy: - copy:
src: b64_latin1 src: b64_latin1
dest: "{{ output_dir }}" dest: "{{ remote_tmp_dir }}"
- stat: - stat:
path: "{{ output_dir }}/from_playbook" path: "{{ remote_tmp_dir }}/from_playbook"
register: from_playbook register: from_playbook
- stat: - stat:
path: "{{ output_dir }}/b64_utf8" path: "{{ remote_tmp_dir }}/b64_utf8"
register: b64_utf8 register: b64_utf8
- stat: - stat:
path: "{{ output_dir }}/b64_latin1" path: "{{ remote_tmp_dir }}/b64_latin1"
register: b64_latin1 register: b64_latin1
# Tests themselves # Tests themselves
- name: copy with utf-8 content in a playbook - name: copy with utf-8 content in a playbook
copy: copy:
content: "{{ simple_accents }}\n" content: "{{ simple_accents }}\n"
dest: "{{ output_dir }}/from_playbook.txt" dest: "{{ remote_tmp_dir }}/from_playbook.txt"
- name: Check that copying utf-8 content matches - name: Check that copying utf-8 content matches
stat: stat:
path: "{{ output_dir }}/from_playbook.txt" path: "{{ remote_tmp_dir }}/from_playbook.txt"
register: results register: results
- assert: - assert:
@ -52,11 +52,11 @@
- name: copy with utf8 in a base64 encoded string - name: copy with utf8 in a base64 encoded string
copy: copy:
content: "{{ utf8_simple_accents|b64decode }}\n" content: "{{ utf8_simple_accents|b64decode }}\n"
dest: "{{ output_dir }}/b64_utf8.txt" dest: "{{ remote_tmp_dir }}/b64_utf8.txt"
- name: Check that utf8 in a base64 string matches - name: Check that utf8 in a base64 string matches
stat: stat:
path: "{{ output_dir }}/b64_utf8.txt" path: "{{ remote_tmp_dir }}/b64_utf8.txt"
register: results register: results
- assert: - assert:
@ -66,11 +66,11 @@
- name: copy with latin1 in a base64 encoded string - name: copy with latin1 in a base64 encoded string
copy: copy:
content: "{{ latin1_simple_accents|b64decode }}\n" content: "{{ latin1_simple_accents|b64decode }}\n"
dest: "{{ output_dir }}/b64_latin1.txt" dest: "{{ remote_tmp_dir }}/b64_latin1.txt"
- name: Check that latin1 in a base64 string matches - name: Check that latin1 in a base64 string matches
stat: stat:
path: "{{ output_dir }}/b64_latin1.txt" path: "{{ remote_tmp_dir }}/b64_latin1.txt"
register: results register: results
- assert: - assert:
@ -83,11 +83,11 @@
- name: Template with a unicode string from the playbook - name: Template with a unicode string from the playbook
template: template:
src: "from_playbook_template.j2" src: "from_playbook_template.j2"
dest: "{{ output_dir }}/from_playbook_template.txt" dest: "{{ remote_tmp_dir }}/from_playbook_template.txt"
- name: Check that writing a template from a playbook var matches - name: Check that writing a template from a playbook var matches
stat: stat:
path: "{{ output_dir }}/from_playbook_template.txt" path: "{{ remote_tmp_dir }}/from_playbook_template.txt"
register: results register: results
- assert: - assert:
@ -97,11 +97,11 @@
- name: Template with utf8 in a base64 encoded string - name: Template with utf8 in a base64 encoded string
template: template:
src: "b64_utf8_template.j2" src: "b64_utf8_template.j2"
dest: "{{ output_dir }}/b64_utf8_template.txt" dest: "{{ remote_tmp_dir }}/b64_utf8_template.txt"
- name: Check that writing a template from a base64 encoded utf8 string matches - name: Check that writing a template from a base64 encoded utf8 string matches
stat: stat:
path: "{{ output_dir }}/b64_utf8_template.txt" path: "{{ remote_tmp_dir }}/b64_utf8_template.txt"
register: results register: results
- assert: - assert:
@ -111,11 +111,11 @@
- name: Template with latin1 in a base64 encoded string - name: Template with latin1 in a base64 encoded string
template: template:
src: "b64_latin1_template.j2" src: "b64_latin1_template.j2"
dest: "{{ output_dir }}/b64_latin1_template.txt" dest: "{{ remote_tmp_dir }}/b64_latin1_template.txt"
- name: Check that writing a template from a base64 encoded latin1 string matches - name: Check that writing a template from a base64 encoded latin1 string matches
stat: stat:
path: "{{ output_dir }}/b64_latin1_template.txt" path: "{{ remote_tmp_dir }}/b64_latin1_template.txt"
register: results register: results
- assert: - assert:

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

@ -60,34 +60,34 @@
- argv_and_string_command.rc == 256 - argv_and_string_command.rc == 256
- set_fact: - set_fact:
output_dir_test: "{{ output_dir }}/test_command_shell" remote_tmp_dir_test: "{{ remote_tmp_dir }}/test_command_shell"
- 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
- name: prep our test script - name: prep our test script
copy: copy:
src: test.sh src: test.sh
dest: "{{ output_dir_test }}" dest: "{{ remote_tmp_dir_test }}"
mode: '0755' mode: '0755'
- name: prep our test script - name: prep our test script
copy: copy:
src: create_afile.sh src: create_afile.sh
dest: "{{ output_dir_test }}" dest: "{{ remote_tmp_dir_test }}"
mode: '0755' mode: '0755'
- name: prep our test script - name: prep our test script
copy: copy:
src: remove_afile.sh src: remove_afile.sh
dest: "{{ output_dir_test }}" dest: "{{ remote_tmp_dir_test }}"
mode: '0755' mode: '0755'
- name: locate bash - name: locate bash
@ -99,7 +99,7 @@
## ##
- name: execute the test.sh script via command - name: execute the test.sh script via command
command: "{{ output_dir_test }}/test.sh" command: "{{ remote_tmp_dir_test }}/test.sh"
register: command_result0 register: command_result0
- name: assert that the script executed correctly - name: assert that the script executed correctly
@ -114,7 +114,7 @@
# FIXME doesn't have the expected stdout. # FIXME doesn't have the expected stdout.
#- name: execute the test.sh script with executable via command #- name: execute the test.sh script with executable via command
# command: "{{output_dir_test }}/test.sh executable={{ bash.stdout }}" # command: "{{remote_tmp_dir_test }}/test.sh executable={{ bash.stdout }}"
# register: command_result1 # register: command_result1
# #
#- name: assert that the script executed correctly with command #- name: assert that the script executed correctly with command
@ -129,13 +129,13 @@
- name: execute the test.sh script with chdir via command - name: execute the test.sh script with chdir via command
command: ./test.sh command: ./test.sh
args: args:
chdir: "{{ output_dir_test }}" chdir: "{{ remote_tmp_dir_test }}"
register: command_result2 register: command_result2
- name: Check invalid chdir - name: Check invalid chdir
command: echo command: echo
args: args:
chdir: "{{ output_dir }}/nope" chdir: "{{ remote_tmp_dir }}/nope"
ignore_errors: yes ignore_errors: yes
register: chdir_invalid register: chdir_invalid
@ -152,13 +152,13 @@
- 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 (check mode) - name: create afile.txt with create_afile.sh via command (check mode)
command: "{{ output_dir_test }}/create_afile.sh {{output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/create_afile.sh {{remote_tmp_dir_test }}/afile.txt"
args: args:
creates: "{{ output_dir_test }}/afile.txt" creates: "{{ remote_tmp_dir_test }}/afile.txt"
register: check_mode_result register: check_mode_result
check_mode: yes check_mode: yes
@ -169,24 +169,24 @@
- name: verify that afile.txt still does not exist - name: verify that afile.txt still does not exist
stat: stat:
path: "{{output_dir_test}}/afile.txt" path: "{{remote_tmp_dir_test}}/afile.txt"
register: stat_result register: stat_result
failed_when: stat_result.stat.exists failed_when: stat_result.stat.exists
- name: create afile.txt with create_afile.sh via command - name: create afile.txt with create_afile.sh via command
command: "{{ output_dir_test }}/create_afile.sh {{output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/create_afile.sh {{remote_tmp_dir_test }}/afile.txt"
args: args:
creates: "{{ output_dir_test }}/afile.txt" creates: "{{ remote_tmp_dir_test }}/afile.txt"
- 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: re-run previous command using creates with globbing (check mode) - name: re-run previous command using creates with globbing (check mode)
command: "{{ output_dir_test }}/create_afile.sh {{ output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/create_afile.sh {{ remote_tmp_dir_test }}/afile.txt"
args: args:
creates: "{{ output_dir_test }}/afile.*" creates: "{{ remote_tmp_dir_test }}/afile.*"
register: check_mode_result register: check_mode_result
check_mode: yes check_mode: yes
@ -196,9 +196,9 @@
- "'skipped' not in check_mode_result" - "'skipped' not in check_mode_result"
- name: re-run previous command using creates with globbing - name: re-run previous command using creates with globbing
command: "{{ output_dir_test }}/create_afile.sh {{ output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/create_afile.sh {{ remote_tmp_dir_test }}/afile.txt"
args: args:
creates: "{{ output_dir_test }}/afile.*" creates: "{{ remote_tmp_dir_test }}/afile.*"
register: command_result3 register: command_result3
- name: assert that creates with globbing is working - name: assert that creates with globbing is working
@ -209,9 +209,9 @@
# removes # removes
- name: remove afile.txt with remote_afile.sh via command (check mode) - name: remove afile.txt with remote_afile.sh via command (check mode)
command: "{{ output_dir_test }}/remove_afile.sh {{ output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/remove_afile.sh {{ remote_tmp_dir_test }}/afile.txt"
args: args:
removes: "{{ output_dir_test }}/afile.txt" removes: "{{ remote_tmp_dir_test }}/afile.txt"
register: check_mode_result register: check_mode_result
check_mode: yes check_mode: yes
@ -222,22 +222,22 @@
- name: verify that afile.txt still exists - name: verify that afile.txt still exists
stat: stat:
path: "{{output_dir_test}}/afile.txt" path: "{{remote_tmp_dir_test}}/afile.txt"
register: stat_result register: stat_result
failed_when: not stat_result.stat.exists failed_when: not stat_result.stat.exists
- name: remove afile.txt with remote_afile.sh via command - name: remove afile.txt with remote_afile.sh via command
command: "{{ output_dir_test }}/remove_afile.sh {{ output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/remove_afile.sh {{ remote_tmp_dir_test }}/afile.txt"
args: args:
removes: "{{ output_dir_test }}/afile.txt" removes: "{{ remote_tmp_dir_test }}/afile.txt"
- name: verify that afile.txt is absent - name: verify that afile.txt is absent
file: path={{output_dir_test}}/afile.txt state=absent file: path={{remote_tmp_dir_test}}/afile.txt state=absent
- name: re-run previous command using removes with globbing (check mode) - name: re-run previous command using removes with globbing (check mode)
command: "{{ output_dir_test }}/remove_afile.sh {{ output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/remove_afile.sh {{ remote_tmp_dir_test }}/afile.txt"
args: args:
removes: "{{ output_dir_test }}/afile.*" removes: "{{ remote_tmp_dir_test }}/afile.*"
register: check_mode_result register: check_mode_result
check_mode: yes check_mode: yes
@ -247,9 +247,9 @@
- "'skipped' not in check_mode_result" - "'skipped' not in check_mode_result"
- name: re-run previous command using removes with globbing - name: re-run previous command using removes with globbing
command: "{{ output_dir_test }}/remove_afile.sh {{ output_dir_test }}/afile.txt" command: "{{ remote_tmp_dir_test }}/remove_afile.sh {{ remote_tmp_dir_test }}/afile.txt"
args: args:
removes: "{{ output_dir_test }}/afile.*" removes: "{{ remote_tmp_dir_test }}/afile.*"
register: command_result4 register: command_result4
- name: assert that removes with globbing is working - name: assert that removes with globbing is working
@ -289,14 +289,14 @@
## ##
- name: Execute the test.sh script - name: Execute the test.sh script
shell: "{{ output_dir_test }}/test.sh" shell: "{{ remote_tmp_dir_test }}/test.sh"
register: shell_result0 register: shell_result0
- name: Assert that the script executed correctly - name: Assert that the script executed correctly
assert: assert:
that: that:
- shell_result0 is changed - shell_result0 is changed
- shell_result0.cmd == '{{ output_dir_test }}/test.sh' - shell_result0.cmd == '{{ remote_tmp_dir_test }}/test.sh'
- shell_result0.rc == 0 - shell_result0.rc == 0
- shell_result0.stderr == '' - shell_result0.stderr == ''
- shell_result0.stdout == 'win' - shell_result0.stdout == 'win'
@ -306,7 +306,7 @@
# FIXME doesn't pass the expected stdout # FIXME doesn't pass the expected stdout
#- name: execute the test.sh script #- name: execute the test.sh script
# shell: "{{output_dir_test }}/test.sh executable={{ bash.stdout }}" # shell: "{{remote_tmp_dir_test }}/test.sh executable={{ bash.stdout }}"
# register: shell_result1 # register: shell_result1
# #
#- name: assert that the shell executed correctly #- name: assert that the shell executed correctly
@ -321,7 +321,7 @@
- name: Execute the test.sh script with chdir - name: Execute the test.sh script with chdir
shell: ./test.sh shell: ./test.sh
args: args:
chdir: "{{ output_dir_test }}" chdir: "{{ remote_tmp_dir_test }}"
register: shell_result2 register: shell_result2
- name: Assert that the shell executed correctly with chdir - name: Assert that the shell executed correctly with chdir
@ -337,25 +337,25 @@
- 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: Execute the test.sh script with chdir - name: Execute the test.sh script with chdir
shell: "{{ output_dir_test }}/test.sh > {{ output_dir_test }}/afile.txt" shell: "{{ remote_tmp_dir_test }}/test.sh > {{ remote_tmp_dir_test }}/afile.txt"
args: args:
chdir: "{{ output_dir_test }}" chdir: "{{ remote_tmp_dir_test }}"
creates: "{{ output_dir_test }}/afile.txt" creates: "{{ remote_tmp_dir_test }}/afile.txt"
- 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
# multiline # multiline
- name: Remove test file previously created - name: Remove test file previously created
file: file:
path: "{{ output_dir_test }}/afile.txt" path: "{{ remote_tmp_dir_test }}/afile.txt"
state: absent state: absent
- name: Execute a shell command using a literal multiline block - name: Execute a shell command using a literal multiline block
@ -381,7 +381,7 @@
- name: Execute a shell command using a literal multiline block with arguments in it - name: Execute a shell command using a literal multiline block with arguments in it
shell: | shell: |
executable="{{ bash.stdout }}" executable="{{ bash.stdout }}"
creates={{ output_dir_test }}/afile.txt creates={{ remote_tmp_dir_test }}/afile.txt
echo "test" echo "test"
register: shell_result6 register: shell_result6
@ -411,14 +411,14 @@
- shell_result7.stdout == 'One\n Two\n Three' - shell_result7.stdout == 'One\n Two\n Three'
- name: execute a shell command with no trailing newline to stdin - name: execute a shell command with no trailing newline to stdin
shell: cat > {{output_dir_test }}/afile.txt shell: cat > {{remote_tmp_dir_test }}/afile.txt
args: args:
stdin: test stdin: test
stdin_add_newline: no stdin_add_newline: no
- name: make sure content matches expected - name: make sure content matches expected
copy: copy:
dest: "{{output_dir_test }}/afile.txt" dest: "{{remote_tmp_dir_test }}/afile.txt"
content: test content: test
register: shell_result7 register: shell_result7
failed_when: failed_when:
@ -426,14 +426,14 @@
shell_result7 is changed shell_result7 is changed
- name: execute a shell command with trailing newline to stdin - name: execute a shell command with trailing newline to stdin
shell: cat > {{output_dir_test }}/afile.txt shell: cat > {{remote_tmp_dir_test }}/afile.txt
args: args:
stdin: test stdin: test
stdin_add_newline: yes stdin_add_newline: yes
- name: make sure content matches expected - name: make sure content matches expected
copy: copy:
dest: "{{output_dir_test }}/afile.txt" dest: "{{remote_tmp_dir_test }}/afile.txt"
content: | content: |
test test
register: shell_result8 register: shell_result8
@ -442,13 +442,13 @@
shell_result8 is changed shell_result8 is changed
- name: execute a shell command with trailing newline to stdin, default - name: execute a shell command with trailing newline to stdin, default
shell: cat > {{output_dir_test }}/afile.txt shell: cat > {{remote_tmp_dir_test }}/afile.txt
args: args:
stdin: test stdin: test
- name: make sure content matches expected - name: make sure content matches expected
copy: copy:
dest: "{{output_dir_test }}/afile.txt" dest: "{{remote_tmp_dir_test }}/afile.txt"
content: | content: |
test test
register: shell_result9 register: shell_result9
@ -458,7 +458,7 @@
- name: remove the previously created file - name: remove the previously created file
file: file:
path: "{{ output_dir_test }}/afile.txt" path: "{{ remote_tmp_dir_test }}/afile.txt"
state: absent state: absent
- name: test warning with command - name: test warning with command
@ -531,31 +531,32 @@
block: block:
- name: Create target folders - name: Create target folders
file: file:
path: '{{output_dir}}/www_root/site' path: '{{remote_tmp_dir}}/www_root/site'
state: directory state: directory
- name: Create symlink - name: Create symlink
file: file:
path: '{{output_dir}}/www' path: '{{remote_tmp_dir}}/www'
state: link state: link
src: '{{output_dir}}/www_root' src: '{{remote_tmp_dir}}/www_root'
- name: check parent using chdir - name: check parent using chdir
shell: dirname "$PWD" shell: dirname "$PWD"
args: args:
chdir: '{{output_dir}}/www/site' chdir: '{{remote_tmp_dir}}/www/site'
register: parent_dir_chdir register: parent_dir_chdir
- name: check parent using cd - name: check parent using cd
shell: cd "{{output_dir}}/www/site" && dirname "$PWD" shell: cd "{{remote_tmp_dir}}/www/site" && dirname "$PWD"
register: parent_dir_cd register: parent_dir_cd
- name: check expected outputs - name: check expected outputs
assert: assert:
that: that:
- parent_dir_chdir.stdout != parent_dir_cd.stdout - parent_dir_chdir.stdout != parent_dir_cd.stdout
- 'parent_dir_cd.stdout == "{{output_dir}}/www"' # These tests use endswith, to get around /private/tmp on macos
- 'parent_dir_chdir.stdout == "{{output_dir}}/www_root"' - 'parent_dir_cd.stdout.endswith(remote_tmp_dir ~ "/www")'
- 'parent_dir_chdir.stdout.endswith(remote_tmp_dir ~ "/www_root")'
- name: Set print error command for Python 2 - name: Set print error command for Python 2
set_fact: set_fact:

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

@ -7,7 +7,7 @@
- set_fact: - set_fact:
local_temp_dir: '{{ tempfile_result.stdout }}' local_temp_dir: '{{ tempfile_result.stdout }}'
remote_dir: '{{ output_dir }}' remote_dir: '{{ remote_tmp_dir }}/copy'
symlinks: symlinks:
ansible-test-abs-link: /tmp/ansible-test-abs-link ansible-test-abs-link: /tmp/ansible-test-abs-link
ansible-test-abs-link-dir: /tmp/ansible-test-abs-link-dir ansible-test-abs-link-dir: /tmp/ansible-test-abs-link-dir

@ -2263,7 +2263,7 @@
- name: fail to copy an encrypted file without the password set - name: fail to copy an encrypted file without the password set
copy: copy:
src: '{{role_path}}/files-different/vault/vault-file' src: '{{role_path}}/files-different/vault/vault-file'
dest: '{{output_dir}}/file' dest: '{{remote_tmp_dir}}/copy/file'
register: fail_copy_encrypted_file register: fail_copy_encrypted_file
ignore_errors: yes # weird failed_when doesn't work in this case ignore_errors: yes # weird failed_when doesn't work in this case
@ -2276,7 +2276,7 @@
- name: fail to copy a directory with an encrypted file without the password - name: fail to copy a directory with an encrypted file without the password
copy: copy:
src: '{{role_path}}/files-different/vault' src: '{{role_path}}/files-different/vault'
dest: '{{output_dir}}' dest: '{{remote_tmp_dir}}/copy'
register: fail_copy_directory_with_enc_file register: fail_copy_directory_with_enc_file
ignore_errors: yes ignore_errors: yes

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

@ -20,13 +20,13 @@
name: setup_pexpect name: setup_pexpect
- name: record the test_command file - name: record the test_command file
set_fact: test_command_file={{output_dir | expanduser}}/test_command.py set_fact: test_command_file={{remote_tmp_dir | expanduser}}/test_command.py
- name: copy script into output directory - name: copy script into output directory
copy: src=test_command.py dest={{test_command_file}} mode=0444 copy: src=test_command.py dest={{test_command_file}} mode=0444
- name: record the output file - name: record the output file
set_fact: output_file={{output_dir}}/foo.txt set_fact: output_file={{remote_tmp_dir}}/foo.txt
- copy: - copy:
content: "foo" content: "foo"
@ -104,7 +104,7 @@
- name: test chdir - name: test chdir
expect: expect:
command: "/bin/sh -c 'pwd && sleep 1'" command: "/bin/sh -c 'pwd && sleep 1'"
chdir: "{{output_dir}}" chdir: "{{remote_tmp_dir}}"
responses: responses:
foo: bar foo: bar
register: chdir_result register: chdir_result
@ -112,7 +112,7 @@
- name: assert chdir works - name: assert chdir works
assert: assert:
that: that:
- "'{{chdir_result.stdout |expanduser | realpath }}' == '{{output_dir | expanduser | realpath}}'" - "'{{chdir_result.stdout |expanduser | realpath }}' == '{{remote_tmp_dir | expanduser | realpath}}'"
- name: test timeout option - name: test timeout option
expect: expect:

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

@ -15,12 +15,12 @@
- name: create a test sub-directory - name: create a test sub-directory
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: directory state: directory
- name: create a file for linking to - name: create a file for linking to
copy: copy:
dest: '{{output_dir}}/file_to_link' dest: '{{remote_tmp_dir_test}}/file_to_link'
content: 'Hello World' content: 'Hello World'
# #
@ -30,7 +30,7 @@
# file raises an error # file raises an error
- name: Try to create a file with directory as dest - name: Try to create a file with directory as dest
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: file state: file
force: False force: False
ignore_errors: True ignore_errors: True
@ -38,7 +38,7 @@
- name: Get stat info to show the directory has not been changed to a file - name: Get stat info to show the directory has not been changed to a file
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file1_dir_stat register: file1_dir_stat
@ -51,8 +51,8 @@
# link raises an error # link raises an error
- name: Try to create a symlink with directory as dest - name: Try to create a symlink with directory as dest
file: file:
src: '{{ output_dir }}/file_to_link' src: '{{ remote_tmp_dir_test }}/file_to_link'
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: link state: link
force: False force: False
ignore_errors: True ignore_errors: True
@ -60,7 +60,7 @@
- name: Get stat info to show the directory has not been changed to a file - name: Get stat info to show the directory has not been changed to a file
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file2_dir_stat register: file2_dir_stat
@ -76,12 +76,12 @@
- copy: - copy:
content: 'test' content: 'test'
dest: '{{ output_dir }}/sub1/passwd' dest: '{{ remote_tmp_dir_test }}/sub1/passwd'
# file raises an error # file raises an error
- name: Try to create a file with directory as dest - name: Try to create a file with directory as dest
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: file state: file
force: True force: True
ignore_errors: True ignore_errors: True
@ -89,7 +89,7 @@
- name: Get stat info to show the directory has not been changed to a file - name: Get stat info to show the directory has not been changed to a file
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file3_dir_stat register: file3_dir_stat
@ -102,8 +102,8 @@
# link raises an error # link raises an error
- name: Try to create a symlink with directory as dest - name: Try to create a symlink with directory as dest
file: file:
src: '{{ output_dir }}/file_to_link' src: '{{ remote_tmp_dir_test }}/file_to_link'
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: link state: link
force: True force: True
ignore_errors: True ignore_errors: True
@ -111,7 +111,7 @@
- name: Get stat info to show the directory has not been changed to a file - name: Get stat info to show the directory has not been changed to a file
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file4_dir_stat register: file4_dir_stat
@ -125,7 +125,7 @@
- name: Cleanup the file that made the directory nonempty - name: Cleanup the file that made the directory nonempty
file: file:
state: 'absent' state: 'absent'
dest: '{{ output_dir }}/sub1/passwd' dest: '{{ remote_tmp_dir_test }}/sub1/passwd'
# #
# Error condition: file cannot even overwrite an empty directory with force=True # Error condition: file cannot even overwrite an empty directory with force=True
@ -134,7 +134,7 @@
# file raises an error # file raises an error
- name: Try to create a file with directory as dest - name: Try to create a file with directory as dest
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: file state: file
force: True force: True
ignore_errors: True ignore_errors: True
@ -142,7 +142,7 @@
- name: Get stat info to show the directory has not been changed to a file - name: Get stat info to show the directory has not been changed to a file
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file5_dir_stat register: file5_dir_stat
@ -159,15 +159,15 @@
# link can overwrite an empty directory with force=True # link can overwrite an empty directory with force=True
- name: Try to create a symlink with directory as dest - name: Try to create a symlink with directory as dest
file: file:
src: '{{ output_dir }}/file_to_link' src: '{{ remote_tmp_dir_test }}/file_to_link'
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: link state: link
force: True force: True
register: file6_result register: file6_result
- name: Get stat info to show the directory has been overwritten - name: Get stat info to show the directory has been overwritten
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file6_dir_stat register: file6_dir_stat
@ -184,12 +184,12 @@
- name: Cleanup the test subdirectory - name: Cleanup the test subdirectory
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: 'absent' state: 'absent'
- name: Re-create the test sub-directory - name: Re-create the test sub-directory
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: 'directory' state: 'directory'
# #
@ -198,8 +198,8 @@
- name: Try to create a hardlink with directory as dest - name: Try to create a hardlink with directory as dest
file: file:
src: '{{ output_dir }}/file_to_link' src: '{{ remote_tmp_dir_test }}/file_to_link'
dest: '{{ output_dir }}/sub1' dest: '{{ remote_tmp_dir_test }}/sub1'
state: hard state: hard
force: False force: False
ignore_errors: True ignore_errors: True
@ -207,13 +207,13 @@
- name: Get stat info to show the directory has not been changed to a file - name: Get stat info to show the directory has not been changed to a file
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file7_dir_stat register: file7_dir_stat
- name: Get stat info to show the link has been created - name: Get stat info to show the link has been created
stat: stat:
path: '{{ output_dir }}/sub1/file_to_link' path: '{{ remote_tmp_dir_test }}/sub1/file_to_link'
follow: False follow: False
register: file7_link_stat register: file7_link_stat
@ -238,7 +238,7 @@
- name: Get initial stat info to compare with later - name: Get initial stat info to compare with later
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file8_initial_dir_stat register: file8_initial_dir_stat
@ -248,14 +248,14 @@
- name: Use touch with directory as dest - name: Use touch with directory as dest
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: touch state: touch
force: False force: False
register: file8_result register: file8_result
- name: Get stat info to show the directory has not been changed to a file - name: Get stat info to show the directory has not been changed to a file
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file8_dir_stat register: file8_dir_stat
@ -268,13 +268,13 @@
- name: Get initial stat info to compare with later - name: Get initial stat info to compare with later
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file11_initial_dir_stat register: file11_initial_dir_stat
- name: Use touch with directory as dest and keep mtime and atime - name: Use touch with directory as dest and keep mtime and atime
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: touch state: touch
force: False force: False
modification_time: preserve modification_time: preserve
@ -283,7 +283,7 @@
- name: Get stat info to show the directory has not been changed - name: Get stat info to show the directory has not been changed
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file11_dir_stat register: file11_dir_stat
@ -300,20 +300,20 @@
# #
- name: Get initial stat info to compare with later - name: Get initial stat info to compare with later
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file9_initial_dir_stat register: file9_initial_dir_stat
- name: Use directory with directory as dest - name: Use directory with directory as dest
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: directory state: directory
force: False force: False
register: file9_result register: file9_result
- name: Get stat info to show the directory has not been changed - name: Get stat info to show the directory has not been changed
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file9_dir_stat register: file9_dir_stat
@ -326,14 +326,14 @@
- name: Use directory with directory as dest and force=True - name: Use directory with directory as dest and force=True
file: file:
dest: '{{output_dir}}/sub1' dest: '{{remote_tmp_dir_test}}/sub1'
state: directory state: directory
force: True force: True
register: file10_result register: file10_result
- name: Get stat info to show the directory has not been changed - name: Get stat info to show the directory has not been changed
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file10_dir_stat register: file10_dir_stat

@ -3,12 +3,12 @@
# #
- name: Cleanup the output directory - name: Cleanup the output directory
file: file:
dest: '{{ output_dir }}' dest: '{{ remote_tmp_dir_test }}'
state: 'absent' state: 'absent'
- name: Recreate the toplevel output dir - name: Recreate the toplevel output dir
file: file:
dest: '{{ output_dir }}' dest: '{{ remote_tmp_dir_test }}'
state: 'directory' state: 'directory'
- name: prep with a basic file to operate on - name: prep with a basic file to operate on

@ -16,7 +16,11 @@
# 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_file={{output_dir}}/foo.txt - set_fact:
remote_tmp_dir_test: '{{ remote_tmp_dir }}/file'
- set_fact:
output_file: '{{remote_tmp_dir_test}}/foo.txt'
# same as expanduser & expandvars called on managed host # same as expanduser & expandvars called on managed host
- command: 'echo {{ output_file }}' - command: 'echo {{ output_file }}'
@ -81,7 +85,7 @@
- "'cannot continue' in ghost_file_result.msg" - "'cannot continue' in ghost_file_result.msg"
- name: verify that we are checking an absent file - name: verify that we are checking an absent file
file: path={{output_dir}}/bar.txt state=absent file: path={{remote_tmp_dir_test}}/bar.txt state=absent
register: file2_result register: file2_result
- name: verify that the file was marked as changed - name: verify that the file was marked as changed
@ -92,7 +96,7 @@
- name: verify we can touch a file - name: verify we can touch a file
file: file:
path: "{{output_dir}}/baz.txt" path: "{{remote_tmp_dir_test}}/baz.txt"
state: touch state: touch
mode: '0644' mode: '0644'
register: file3_result register: file3_result
@ -105,7 +109,7 @@
- "file3_result.mode == '0644'" - "file3_result.mode == '0644'"
- name: change file mode - name: change file mode
file: path={{output_dir}}/baz.txt mode=0600 file: path={{remote_tmp_dir_test}}/baz.txt mode=0600
register: file4_result register: file4_result
- name: verify that the file was marked as changed - name: verify that the file was marked as changed
@ -116,7 +120,7 @@
- name: define file to verify chattr/lsattr with - name: define file to verify chattr/lsattr with
set_fact: set_fact:
attributes_file: "{{ output_dir }}/attributes.txt" attributes_file: "{{ remote_tmp_dir_test }}/attributes.txt"
attributes_supported: no attributes_supported: no
- name: create file to verify chattr/lsattr with - name: create file to verify chattr/lsattr with
@ -150,13 +154,13 @@
- "'A' not in attribute_A_unset.stdout_lines[0].split()[0]" - "'A' not in attribute_A_unset.stdout_lines[0].split()[0]"
- name: explicitly set file attribute "A" - name: explicitly set file attribute "A"
file: path={{output_dir}}/baz.txt attributes=A file: path={{remote_tmp_dir_test}}/baz.txt attributes=A
register: file_attributes_result register: file_attributes_result
ignore_errors: True ignore_errors: True
when: attributes_supported when: attributes_supported
- name: add file attribute "A" - name: add file attribute "A"
file: path={{output_dir}}/baz.txt attributes=+A file: path={{remote_tmp_dir_test}}/baz.txt attributes=+A
register: file_attributes_result_2 register: file_attributes_result_2
when: file_attributes_result is changed when: file_attributes_result is changed
@ -167,12 +171,12 @@
when: file_attributes_result is changed when: file_attributes_result is changed
- name: remove file attribute "A" - name: remove file attribute "A"
file: path={{output_dir}}/baz.txt attributes=-A file: path={{remote_tmp_dir_test}}/baz.txt attributes=-A
register: file_attributes_result_3 register: file_attributes_result_3
ignore_errors: True ignore_errors: True
- name: explicitly remove file attributes - name: explicitly remove file attributes
file: path={{output_dir}}/baz.txt attributes="" file: path={{remote_tmp_dir_test}}/baz.txt attributes=""
register: file_attributes_result_4 register: file_attributes_result_4
when: file_attributes_result_3 is changed when: file_attributes_result_3 is changed
@ -195,18 +199,18 @@
notify: remove groups notify: remove groups
- name: change ownership and group - name: change ownership and group
file: path={{output_dir}}/baz.txt owner=1234 group=1234 file: path={{remote_tmp_dir_test}}/baz.txt owner=1234 group=1234
- name: Get stat info to check atime later - name: Get stat info to check atime later
stat: path={{output_dir}}/baz.txt stat: path={{remote_tmp_dir_test}}/baz.txt
register: file_attributes_result_5_before register: file_attributes_result_5_before
- name: updates access time - name: updates access time
file: path={{output_dir}}/baz.txt access_time=now file: path={{remote_tmp_dir_test}}/baz.txt access_time=now
register: file_attributes_result_5 register: file_attributes_result_5
- name: Get stat info to check atime later - name: Get stat info to check atime later
stat: path={{output_dir}}/baz.txt stat: path={{remote_tmp_dir_test}}/baz.txt
register: file_attributes_result_5_after register: file_attributes_result_5_after
- name: verify that the file was marked as changed and atime changed - name: verify that the file was marked as changed and atime changed
@ -239,7 +243,7 @@
file: path=/tmp/worldwritable state=absent file: path=/tmp/worldwritable state=absent
- name: create hard link to file - name: create hard link to file
file: src={{output_file}} dest={{output_dir}}/hard.txt state=hard file: src={{output_file}} dest={{remote_tmp_dir_test}}/hard.txt state=hard
register: file6_result register: file6_result
- name: verify that the file was marked as changed - name: verify that the file was marked as changed
@ -249,7 +253,7 @@
- name: touch a hard link - name: touch a hard link
file: file:
dest: '{{ output_dir }}/hard.txt' dest: '{{ remote_tmp_dir_test }}/hard.txt'
state: 'touch' state: 'touch'
register: file6_touch_result register: file6_touch_result
@ -263,7 +267,7 @@
register: hlstat1 register: hlstat1
- name: stat2 - name: stat2
stat: path={{output_dir}}/hard.txt stat: path={{remote_tmp_dir_test}}/hard.txt
register: hlstat2 register: hlstat2
- name: verify that hard link is still the same after timestamp updated - name: verify that hard link is still the same after timestamp updated
@ -272,7 +276,7 @@
- "hlstat1.stat.inode == hlstat2.stat.inode" - "hlstat1.stat.inode == hlstat2.stat.inode"
- name: create hard link to file 2 - name: create hard link to file 2
file: src={{output_file}} dest={{output_dir}}/hard.txt state=hard file: src={{output_file}} dest={{remote_tmp_dir_test}}/hard.txt state=hard
register: hlink_result register: hlink_result
- name: verify that hard link creation is idempotent - name: verify that hard link creation is idempotent
@ -281,7 +285,7 @@
- "hlink_result.changed == False" - "hlink_result.changed == False"
- name: Change mode on a hard link - name: Change mode on a hard link
file: src={{output_file}} dest={{output_dir}}/hard.txt mode=0701 file: src={{output_file}} dest={{remote_tmp_dir_test}}/hard.txt mode=0701
register: file6_mode_change register: file6_mode_change
- name: verify that the hard link was touched - name: verify that the hard link was touched
@ -294,7 +298,7 @@
register: hlstat1 register: hlstat1
- name: stat2 - name: stat2
stat: path={{output_dir}}/hard.txt stat: path={{remote_tmp_dir_test}}/hard.txt
register: hlstat2 register: hlstat2
- name: verify that hard link is still the same after timestamp updated - name: verify that hard link is still the same after timestamp updated
@ -304,7 +308,7 @@
- "hlstat1.stat.mode == '0701'" - "hlstat1.stat.mode == '0701'"
- name: create a directory - name: create a directory
file: path={{output_dir}}/foobar state=directory file: path={{remote_tmp_dir_test}}/foobar state=directory
register: file7_result register: file7_result
- name: verify that the file was marked as changed - name: verify that the file was marked as changed
@ -324,19 +328,19 @@
ignore_errors: true ignore_errors: true
- name: remove directory foobar - name: remove directory foobar
file: path={{output_dir}}/foobar state=absent file: path={{remote_tmp_dir_test}}/foobar state=absent
- name: remove file foo.txt - name: remove file foo.txt
file: path={{output_dir}}/foo.txt state=absent file: path={{remote_tmp_dir_test}}/foo.txt state=absent
- name: remove file bar.txt - name: remove file bar.txt
file: path={{output_dir}}/foo.txt state=absent file: path={{remote_tmp_dir_test}}/foo.txt state=absent
- name: remove file baz.txt - name: remove file baz.txt
file: path={{output_dir}}/foo.txt state=absent file: path={{remote_tmp_dir_test}}/foo.txt state=absent
- name: copy directory structure over - name: copy directory structure over
copy: src=foobar dest={{output_dir}} copy: src=foobar dest={{remote_tmp_dir_test}}
- name: check what would be removed if folder state was absent and diff is enabled - name: check what would be removed if folder state was absent and diff is enabled
file: file:
@ -345,8 +349,8 @@
check_mode: yes check_mode: yes
diff: yes diff: yes
with_items: with_items:
- "{{ output_dir }}" - "{{ remote_tmp_dir_test }}"
- "{{ output_dir }}/foobar/fileA" - "{{ remote_tmp_dir_test }}/foobar/fileA"
register: folder_absent_result register: folder_absent_result
- name: 'assert that the "absent" state lists expected files and folders for only directories' - name: 'assert that the "absent" state lists expected files and folders for only directories'
@ -361,10 +365,10 @@
test_file: "{{ folder_absent_result.results[0].path }}/foobar/fileA" test_file: "{{ folder_absent_result.results[0].path }}/foobar/fileA"
- name: Change ownership of a directory with recurse=no(default) - name: Change ownership of a directory with recurse=no(default)
file: path={{output_dir}}/foobar owner=1234 file: path={{remote_tmp_dir_test}}/foobar owner=1234
- name: verify that the permission of the directory was set - name: verify that the permission of the directory was set
file: path={{output_dir}}/foobar state=directory file: path={{remote_tmp_dir_test}}/foobar state=directory
register: file8_result register: file8_result
- name: assert that the directory has changed to have owner 1234 - name: assert that the directory has changed to have owner 1234
@ -373,7 +377,7 @@
- "file8_result.uid == 1234" - "file8_result.uid == 1234"
- name: verify that the permission of a file under the directory was not set - name: verify that the permission of a file under the directory was not set
file: path={{output_dir}}/foobar/fileA state=file file: path={{remote_tmp_dir_test}}/foobar/fileA state=file
register: file9_result register: file9_result
- name: assert the file owner has not changed to 1234 - name: assert the file owner has not changed to 1234
@ -387,10 +391,10 @@
uid: 1235 uid: 1235
- name: change the ownership of a directory with recurse=yes - name: change the ownership of a directory with recurse=yes
file: path={{output_dir}}/foobar owner=1235 recurse=yes file: path={{remote_tmp_dir_test}}/foobar owner=1235 recurse=yes
- name: verify that the permission of the directory was set - name: verify that the permission of the directory was set
file: path={{output_dir}}/foobar state=directory file: path={{remote_tmp_dir_test}}/foobar state=directory
register: file10_result register: file10_result
- name: assert that the directory has changed to have owner 1235 - name: assert that the directory has changed to have owner 1235
@ -399,7 +403,7 @@
- "file10_result.uid == 1235" - "file10_result.uid == 1235"
- name: verify that the permission of a file under the directory was not set - name: verify that the permission of a file under the directory was not set
file: path={{output_dir}}/foobar/fileA state=file file: path={{remote_tmp_dir_test}}/foobar/fileA state=file
register: file11_result register: file11_result
- name: assert that the file has changed to have owner 1235 - name: assert that the file has changed to have owner 1235
@ -408,7 +412,7 @@
- "file11_result.uid == 1235" - "file11_result.uid == 1235"
- name: remove directory foobar - name: remove directory foobar
file: path={{output_dir}}/foobar state=absent file: path={{remote_tmp_dir_test}}/foobar state=absent
register: file14_result register: file14_result
- name: verify that the directory was removed - name: verify that the directory was removed
@ -418,7 +422,7 @@
- 'file14_result.state == "absent"' - 'file14_result.state == "absent"'
- name: create a test sub-directory - name: create a test sub-directory
file: dest={{output_dir}}/sub1 state=directory file: dest={{remote_tmp_dir_test}}/sub1 state=directory
register: file15_result register: file15_result
- name: verify that the new directory was created - name: verify that the new directory was created
@ -428,7 +432,7 @@
- 'file15_result.state == "directory"' - 'file15_result.state == "directory"'
- name: create test files in the sub-directory - name: create test files in the sub-directory
file: dest={{output_dir}}/sub1/{{item}} state=touch file: dest={{remote_tmp_dir_test}}/sub1/{{item}} state=touch
with_items: with_items:
- file1 - file1
- file2 - file2
@ -443,7 +447,7 @@
with_items: "{{file16_result.results}}" with_items: "{{file16_result.results}}"
- name: test file creation with symbolic mode - name: test file creation with symbolic mode
file: dest={{output_dir}}/test_symbolic state=touch mode=u=rwx,g=rwx,o=rwx file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=u=rwx,g=rwx,o=rwx
register: result register: result
- name: assert file mode - name: assert file mode
@ -452,7 +456,7 @@
- result.mode == '0777' - result.mode == '0777'
- name: modify symbolic mode for all - name: modify symbolic mode for all
file: dest={{output_dir}}/test_symbolic state=touch mode=a=r file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=a=r
register: result register: result
- name: assert file mode - name: assert file mode
@ -461,7 +465,7 @@
- result.mode == '0444' - result.mode == '0444'
- name: modify symbolic mode for owner - name: modify symbolic mode for owner
file: dest={{output_dir}}/test_symbolic state=touch mode=u+w file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=u+w
register: result register: result
- name: assert file mode - name: assert file mode
@ -470,7 +474,7 @@
- result.mode == '0644' - result.mode == '0644'
- name: modify symbolic mode for group - name: modify symbolic mode for group
file: dest={{output_dir}}/test_symbolic state=touch mode=g+w file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=g+w
register: result register: result
- name: assert file mode - name: assert file mode
@ -479,7 +483,7 @@
- result.mode == '0664' - result.mode == '0664'
- name: modify symbolic mode for world - name: modify symbolic mode for world
file: dest={{output_dir}}/test_symbolic state=touch mode=o+w file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=o+w
register: result register: result
- name: assert file mode - name: assert file mode
@ -488,7 +492,7 @@
- result.mode == '0666' - result.mode == '0666'
- name: modify symbolic mode for owner - name: modify symbolic mode for owner
file: dest={{output_dir}}/test_symbolic state=touch mode=u+x file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=u+x
register: result register: result
- name: assert file mode - name: assert file mode
@ -497,7 +501,7 @@
- result.mode == '0766' - result.mode == '0766'
- name: modify symbolic mode for group - name: modify symbolic mode for group
file: dest={{output_dir}}/test_symbolic state=touch mode=g+x file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=g+x
register: result register: result
- name: assert file mode - name: assert file mode
@ -506,7 +510,7 @@
- result.mode == '0776' - result.mode == '0776'
- name: modify symbolic mode for world - name: modify symbolic mode for world
file: dest={{output_dir}}/test_symbolic state=touch mode=o+x file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=o+x
register: result register: result
- name: assert file mode - name: assert file mode
@ -515,7 +519,7 @@
- result.mode == '0777' - result.mode == '0777'
- name: remove symbolic mode for world - name: remove symbolic mode for world
file: dest={{output_dir}}/test_symbolic state=touch mode=o-wx file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=o-wx
register: result register: result
- name: assert file mode - name: assert file mode
@ -524,7 +528,7 @@
- result.mode == '0774' - result.mode == '0774'
- name: remove symbolic mode for group - name: remove symbolic mode for group
file: dest={{output_dir}}/test_symbolic state=touch mode=g-wx file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=g-wx
register: result register: result
- name: assert file mode - name: assert file mode
@ -533,7 +537,7 @@
- result.mode == '0744' - result.mode == '0744'
- name: remove symbolic mode for owner - name: remove symbolic mode for owner
file: dest={{output_dir}}/test_symbolic state=touch mode=u-wx file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=u-wx
register: result register: result
- name: assert file mode - name: assert file mode
@ -542,7 +546,7 @@
- result.mode == '0444' - result.mode == '0444'
- name: set sticky bit with symbolic mode - name: set sticky bit with symbolic mode
file: dest={{output_dir}}/test_symbolic state=touch mode=o+t file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=o+t
register: result register: result
- name: assert file mode - name: assert file mode
@ -551,7 +555,7 @@
- result.mode == '01444' - result.mode == '01444'
- name: remove sticky bit with symbolic mode - name: remove sticky bit with symbolic mode
file: dest={{output_dir}}/test_symbolic state=touch mode=o-t file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=o-t
register: result register: result
- name: assert file mode - name: assert file mode
@ -560,7 +564,7 @@
- result.mode == '0444' - result.mode == '0444'
- name: add setgid with symbolic mode - name: add setgid with symbolic mode
file: dest={{output_dir}}/test_symbolic state=touch mode=g+s file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=g+s
register: result register: result
- name: assert file mode - name: assert file mode
@ -569,7 +573,7 @@
- result.mode == '02444' - result.mode == '02444'
- name: remove setgid with symbolic mode - name: remove setgid with symbolic mode
file: dest={{output_dir}}/test_symbolic state=touch mode=g-s file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=g-s
register: result register: result
- name: assert file mode - name: assert file mode
@ -578,7 +582,7 @@
- result.mode == '0444' - result.mode == '0444'
- name: add setuid with symbolic mode - name: add setuid with symbolic mode
file: dest={{output_dir}}/test_symbolic state=touch mode=u+s file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=u+s
register: result register: result
- name: assert file mode - name: assert file mode
@ -587,7 +591,7 @@
- result.mode == '04444' - result.mode == '04444'
- name: remove setuid with symbolic mode - name: remove setuid with symbolic mode
file: dest={{output_dir}}/test_symbolic state=touch mode=u-s file: dest={{remote_tmp_dir_test}}/test_symbolic state=touch mode=u-s
register: result register: result
- name: assert file mode - name: assert file mode
@ -704,7 +708,7 @@
- group_gid_exists.warnings is not defined - group_gid_exists.warnings is not defined
# https://github.com/ansible/ansible/issues/50943 # https://github.com/ansible/ansible/issues/50943
# Need to use /tmp as nobody can't access output_dir at all # Need to use /tmp as nobody can't access remote_tmp_dir_test at all
- name: create file as root with all write permissions - name: create file as root with all write permissions
file: dest=/tmp/write_utime state=touch mode=0666 owner={{ansible_user_id}} file: dest=/tmp/write_utime state=touch mode=0666 owner={{ansible_user_id}}
@ -743,39 +747,39 @@
# Follow + recursive tests # Follow + recursive tests
- name: create a toplevel directory - name: create a toplevel directory
file: path={{output_dir}}/test_follow_rec state=directory mode=0755 file: path={{remote_tmp_dir_test}}/test_follow_rec state=directory mode=0755
- name: create a file outside of the toplevel - name: create a file outside of the toplevel
file: path={{output_dir}}/test_follow_rec_target_file state=touch mode=0700 file: path={{remote_tmp_dir_test}}/test_follow_rec_target_file state=touch mode=0700
- name: create a directory outside of the toplevel - name: create a directory outside of the toplevel
file: path={{output_dir}}/test_follow_rec_target_dir state=directory mode=0700 file: path={{remote_tmp_dir_test}}/test_follow_rec_target_dir state=directory mode=0700
- name: create a file inside of the link target directory - name: create a file inside of the link target directory
file: path={{output_dir}}/test_follow_rec_target_dir/foo state=touch mode=0700 file: path={{remote_tmp_dir_test}}/test_follow_rec_target_dir/foo state=touch mode=0700
- name: create a symlink to the file - name: create a symlink to the file
file: path={{output_dir}}/test_follow_rec/test_link state=link src="../test_follow_rec_target_file" file: path={{remote_tmp_dir_test}}/test_follow_rec/test_link state=link src="../test_follow_rec_target_file"
- name: create a symlink to the directory - name: create a symlink to the directory
file: path={{output_dir}}/test_follow_rec/test_link_dir state=link src="../test_follow_rec_target_dir" file: path={{remote_tmp_dir_test}}/test_follow_rec/test_link_dir state=link src="../test_follow_rec_target_dir"
- name: create a symlink to a nonexistent file - name: create a symlink to a nonexistent file
file: path={{output_dir}}/test_follow_rec/nonexistent state=link src=does_not_exist force=True file: path={{remote_tmp_dir_test}}/test_follow_rec/nonexistent state=link src=does_not_exist force=True
- name: try to change permissions without following symlinks - name: try to change permissions without following symlinks
file: path={{output_dir}}/test_follow_rec follow=False mode="a-x" recurse=True file: path={{remote_tmp_dir_test}}/test_follow_rec follow=False mode="a-x" recurse=True
- name: stat the link file target - name: stat the link file target
stat: path={{output_dir}}/test_follow_rec_target_file stat: path={{remote_tmp_dir_test}}/test_follow_rec_target_file
register: file_result register: file_result
- name: stat the link dir target - name: stat the link dir target
stat: path={{output_dir}}/test_follow_rec_target_dir stat: path={{remote_tmp_dir_test}}/test_follow_rec_target_dir
register: dir_result register: dir_result
- name: stat the file inside the link dir target - name: stat the file inside the link dir target
stat: path={{output_dir}}/test_follow_rec_target_dir/foo stat: path={{remote_tmp_dir_test}}/test_follow_rec_target_dir/foo
register: file_in_dir_result register: file_in_dir_result
- name: assert that the link targets were unmodified - name: assert that the link targets were unmodified
@ -786,18 +790,18 @@
- file_in_dir_result.stat.mode == '0700' - file_in_dir_result.stat.mode == '0700'
- name: try to change permissions with following symlinks - name: try to change permissions with following symlinks
file: path={{output_dir}}/test_follow_rec follow=True mode="a-x" recurse=True file: path={{remote_tmp_dir_test}}/test_follow_rec follow=True mode="a-x" recurse=True
- name: stat the link file target - name: stat the link file target
stat: path={{output_dir}}/test_follow_rec_target_file stat: path={{remote_tmp_dir_test}}/test_follow_rec_target_file
register: file_result register: file_result
- name: stat the link dir target - name: stat the link dir target
stat: path={{output_dir}}/test_follow_rec_target_dir stat: path={{remote_tmp_dir_test}}/test_follow_rec_target_dir
register: dir_result register: dir_result
- name: stat the file inside the link dir target - name: stat the file inside the link dir target
stat: path={{output_dir}}/test_follow_rec_target_dir/foo stat: path={{remote_tmp_dir_test}}/test_follow_rec_target_dir/foo
register: file_in_dir_result register: file_in_dir_result
- name: assert that the link targets were modified - name: assert that the link targets were modified
@ -821,7 +825,7 @@
- name: Test missing src - name: Test missing src
file: file:
dest: "{{ output_dir }}/hard.txt" dest: "{{ remote_tmp_dir_test }}/hard.txt"
state: hard state: hard
register: file_error2 register: file_error2
ignore_errors: yes ignore_errors: yes
@ -834,7 +838,7 @@
- name: Test non-existing src - name: Test non-existing src
file: file:
src: non-existing-file-that-does-not-exist.txt src: non-existing-file-that-does-not-exist.txt
dest: "{{ output_dir }}/hard.txt" dest: "{{ remote_tmp_dir_test }}/hard.txt"
state: hard state: hard
register: file_error3 register: file_error3
ignore_errors: yes ignore_errors: yes
@ -843,7 +847,7 @@
that: that:
- "file_error3 is failed" - "file_error3 is failed"
- "file_error3.msg == 'src does not exist'" - "file_error3.msg == 'src does not exist'"
- "file_error3.dest == '{{ output_dir }}/hard.txt' | expanduser" - "file_error3.dest == '{{ remote_tmp_dir_test }}/hard.txt' | expanduser"
- "file_error3.src == 'non-existing-file-that-does-not-exist.txt'" - "file_error3.src == 'non-existing-file-that-does-not-exist.txt'"
- block: - block:

@ -20,7 +20,7 @@
import_tasks: initialize.yml import_tasks: initialize.yml
- name: touch a file for testing - name: touch a file for testing
file: path={{output_dir}}/foo-se.txt state=touch file: path={{remote_tmp_dir_test}}/foo-se.txt state=touch
register: file_se_result register: file_se_result
- name: verify that the file was marked as changed - name: verify that the file was marked as changed
@ -30,4 +30,4 @@
- "file_se_result.secontext == 'unconfined_u:object_r:admin_home_t:s0'" - "file_se_result.secontext == 'unconfined_u:object_r:admin_home_t:s0'"
- name: remove the file used for testing - name: remove the file used for testing
file: path={{output_dir}}/foo-se.txt state=absent file: path={{remote_tmp_dir_test}}/foo-se.txt state=absent

@ -7,12 +7,12 @@
# Basic absolute symlink to a file # Basic absolute symlink to a file
# #
- name: create soft link to file - name: create soft link to file
file: src={{output_file}} dest={{output_dir}}/soft.txt state=link file: src={{output_file}} dest={{remote_tmp_dir_test}}/soft.txt state=link
register: file1_result register: file1_result
- name: Get stat info for the link - name: Get stat info for the link
stat: stat:
path: '{{ output_dir }}/soft.txt' path: '{{ remote_tmp_dir_test }}/soft.txt'
follow: False follow: False
register: file1_link_stat register: file1_link_stat
@ -27,12 +27,12 @@
# Change an absolute soft link into a relative soft link # Change an absolute soft link into a relative soft link
# #
- name: change soft link to relative - name: change soft link to relative
file: src={{output_file|basename}} dest={{output_dir}}/soft.txt state=link file: src={{output_file|basename}} dest={{remote_tmp_dir_test}}/soft.txt state=link
register: file2_result register: file2_result
- name: Get stat info for the link - name: Get stat info for the link
stat: stat:
path: '{{ output_dir }}/soft.txt' path: '{{ remote_tmp_dir_test }}/soft.txt'
follow: False follow: False
register: file2_link_stat register: file2_link_stat
@ -49,12 +49,12 @@
# Check that creating the soft link a second time was idempotent # Check that creating the soft link a second time was idempotent
# #
- name: soft link idempotency check - name: soft link idempotency check
file: src={{output_file|basename}} dest={{output_dir}}/soft.txt state=link file: src={{output_file|basename}} dest={{remote_tmp_dir_test}}/soft.txt state=link
register: file3_result register: file3_result
- name: Get stat info for the link - name: Get stat info for the link
stat: stat:
path: '{{ output_dir }}/soft.txt' path: '{{ remote_tmp_dir_test }}/soft.txt'
follow: False follow: False
register: file3_link_stat register: file3_link_stat
@ -71,7 +71,7 @@
- name: fail to create soft link to non existent file - name: fail to create soft link to non existent file
file: file:
src: '/nonexistent' src: '/nonexistent'
dest: '{{output_dir}}/soft2.txt' dest: '{{remote_tmp_dir_test}}/soft2.txt'
state: 'link' state: 'link'
force: False force: False
register: file4_result register: file4_result
@ -85,14 +85,14 @@
- name: force creation soft link to non existent - name: force creation soft link to non existent
file: file:
src: '/nonexistent' src: '/nonexistent'
dest: '{{ output_dir}}/soft2.txt' dest: '{{ remote_tmp_dir_test}}/soft2.txt'
state: 'link' state: 'link'
force: True force: True
register: file5_result register: file5_result
- name: Get stat info for the link - name: Get stat info for the link
stat: stat:
path: '{{ output_dir }}/soft2.txt' path: '{{ remote_tmp_dir_test }}/soft2.txt'
follow: False follow: False
register: file5_link_stat register: file5_link_stat
@ -106,7 +106,7 @@
- name: Prove idempotence of force creation soft link to non existent - name: Prove idempotence of force creation soft link to non existent
file: file:
src: '/nonexistent' src: '/nonexistent'
dest: '{{ output_dir }}/soft2.txt' dest: '{{ remote_tmp_dir_test }}/soft2.txt'
state: 'link' state: 'link'
force: True force: True
register: file6a_result register: file6a_result
@ -207,19 +207,19 @@
- name: create soft link to directory using absolute path - name: create soft link to directory using absolute path
file: file:
src: '/' src: '/'
dest: '{{ output_dir }}/root' dest: '{{ remote_tmp_dir_test }}/root'
state: 'link' state: 'link'
register: file6_result register: file6_result
- name: Get stat info for the link - name: Get stat info for the link
stat: stat:
path: '{{ output_dir }}/root' path: '{{ remote_tmp_dir_test }}/root'
follow: False follow: False
register: file6_link_stat register: file6_link_stat
- name: Get stat info for the pointed to file - name: Get stat info for the pointed to file
stat: stat:
path: '{{ output_dir }}/root' path: '{{ remote_tmp_dir_test }}/root'
follow: True follow: True
register: file6_links_dest_stat register: file6_links_dest_stat
@ -248,41 +248,41 @@
# Relative link to file # Relative link to file
- name: create a test sub-directory to link to - name: create a test sub-directory to link to
file: file:
dest: '{{ output_dir }}/sub1' dest: '{{ remote_tmp_dir_test }}/sub1'
state: 'directory' state: 'directory'
- name: create a file to link to in the test sub-directory - name: create a file to link to in the test sub-directory
file: file:
dest: '{{ output_dir }}/sub1/file1' dest: '{{ remote_tmp_dir_test }}/sub1/file1'
state: 'touch' state: 'touch'
- name: create another test sub-directory to place links within - name: create another test sub-directory to place links within
file: file:
dest: '{{output_dir}}/sub2' dest: '{{remote_tmp_dir_test}}/sub2'
state: 'directory' state: 'directory'
- name: create soft link to relative file - name: create soft link to relative file
file: file:
src: '../sub1/file1' src: '../sub1/file1'
dest: '{{ output_dir }}/sub2/link1' dest: '{{ remote_tmp_dir_test }}/sub2/link1'
state: 'link' state: 'link'
register: file7_result register: file7_result
- name: Get stat info for the link - name: Get stat info for the link
stat: stat:
path: '{{ output_dir }}/sub2/link1' path: '{{ remote_tmp_dir_test }}/sub2/link1'
follow: False follow: False
register: file7_link_stat register: file7_link_stat
- name: Get stat info for the pointed to file - name: Get stat info for the pointed to file
stat: stat:
path: '{{ output_dir }}/sub2/link1' path: '{{ remote_tmp_dir_test }}/sub2/link1'
follow: True follow: True
register: file7_links_dest_stat register: file7_links_dest_stat
- name: Get stat info for the file we intend to point to - name: Get stat info for the file we intend to point to
stat: stat:
path: '{{ output_dir }}/sub1/file1' path: '{{ remote_tmp_dir_test }}/sub1/file1'
follow: False follow: False
register: file7_dest_stat register: file7_dest_stat
@ -302,25 +302,25 @@
- name: create soft link to relative directory - name: create soft link to relative directory
file: file:
src: sub1 src: sub1
dest: '{{ output_dir }}/sub1-link' dest: '{{ remote_tmp_dir_test }}/sub1-link'
state: 'link' state: 'link'
register: file8_result register: file8_result
- name: Get stat info for the link - name: Get stat info for the link
stat: stat:
path: '{{ output_dir }}/sub1-link' path: '{{ remote_tmp_dir_test }}/sub1-link'
follow: False follow: False
register: file8_link_stat register: file8_link_stat
- name: Get stat info for the pointed to file - name: Get stat info for the pointed to file
stat: stat:
path: '{{ output_dir }}/sub1-link' path: '{{ remote_tmp_dir_test }}/sub1-link'
follow: True follow: True
register: file8_links_dest_stat register: file8_links_dest_stat
- name: Get stat info for the file we intend to point to - name: Get stat info for the file we intend to point to
stat: stat:
path: '{{ output_dir }}/sub1' path: '{{ remote_tmp_dir_test }}/sub1'
follow: False follow: False
register: file8_dest_stat register: file8_dest_stat
@ -341,26 +341,26 @@
- name: create a test file - name: create a test file
copy: copy:
dest: '{{output_dir}}/test_follow' dest: '{{remote_tmp_dir_test}}/test_follow'
content: 'this is a test file\n' content: 'this is a test file\n'
mode: 0666 mode: 0666
- name: create a symlink to the test file - name: create a symlink to the test file
file: file:
path: '{{output_dir}}/test_follow_link' path: '{{remote_tmp_dir_test}}/test_follow_link'
src: './test_follow' src: './test_follow'
state: 'link' state: 'link'
- name: modify the permissions on the link using follow=yes - name: modify the permissions on the link using follow=yes
file: file:
path: '{{output_dir}}/test_follow_link' path: '{{remote_tmp_dir_test}}/test_follow_link'
mode: 0644 mode: 0644
follow: yes follow: yes
register: file9_result register: file9_result
- name: stat the link target - name: stat the link target
stat: stat:
path: '{{output_dir}}/test_follow' path: '{{remote_tmp_dir_test}}/test_follow'
register: file9_stat register: file9_stat
- name: assert that the chmod worked - name: assert that the chmod worked
@ -374,7 +374,7 @@
# #
- name: attempt to modify the permissions of the link itself - name: attempt to modify the permissions of the link itself
file: file:
path: '{{output_dir}}/test_follow_link' path: '{{remote_tmp_dir_test}}/test_follow_link'
src: './test_follow' src: './test_follow'
state: 'link' state: 'link'
mode: 0600 mode: 0600
@ -385,7 +385,7 @@
# Just check that the underlying file was not changed # Just check that the underlying file was not changed
- name: stat the link target - name: stat the link target
stat: stat:
path: '{{output_dir}}/test_follow' path: '{{remote_tmp_dir_test}}/test_follow'
register: file10_target_stat register: file10_target_stat
- name: assert that the link target was unmodified - name: assert that the link target was unmodified
@ -399,19 +399,19 @@
- name: Create a testing file - name: Create a testing file
file: file:
path: "{{ output_dir }}/test_follow1" path: "{{ remote_tmp_dir_test }}/test_follow1"
state: touch state: touch
- name: Create a symlink and change mode of the original file, since follow == yes by default - name: Create a symlink and change mode of the original file, since follow == yes by default
file: file:
src: "{{ output_dir }}/test_follow1" src: "{{ remote_tmp_dir_test }}/test_follow1"
dest: "{{ output_dir }}/test_follow1_link" dest: "{{ remote_tmp_dir_test }}/test_follow1_link"
state: link state: link
mode: 0700 mode: 0700
- name: stat the original file - name: stat the original file
stat: stat:
path: "{{ output_dir }}/test_follow1" path: "{{ remote_tmp_dir_test }}/test_follow1"
register: stat_out register: stat_out
- name: Check if the mode of the original file was set - name: Check if the mode of the original file was set
@ -425,8 +425,8 @@
path: "{{ item }}" path: "{{ item }}"
state: absent state: absent
loop: loop:
- "{{ output_dir }}/test_follow1" - "{{ remote_tmp_dir_test }}/test_follow1"
- "{{ output_dir }}/test_follow1_link" - "{{ remote_tmp_dir_test }}/test_follow1_link"
# END #56928 # END #56928
@ -435,7 +435,7 @@
- name: Specify src without state - name: Specify src without state
file: file:
src: "{{ output_file }}" src: "{{ output_file }}"
dest: "{{ output_dir }}/link.txt" dest: "{{ remote_tmp_dir_test }}/link.txt"
ignore_errors: yes ignore_errors: yes
register: src_state register: src_state
@ -448,35 +448,35 @@
# Test creating a symlink when the destination exists and is a file # Test creating a symlink when the destination exists and is a file
- name: create a test file - name: create a test file
copy: copy:
dest: '{{ output_dir }}/file.txt' dest: '{{ remote_tmp_dir_test }}/file.txt'
content: 'this is a test file\n' content: 'this is a test file\n'
mode: 0666 mode: 0666
- name: Create a symlink with dest already a file - name: Create a symlink with dest already a file
file: file:
src: '{{ output_file }}' src: '{{ output_file }}'
dest: '{{ output_dir }}/file.txt' dest: '{{ remote_tmp_dir_test }}/file.txt'
state: link state: link
ignore_errors: true ignore_errors: true
register: dest_is_existing_file_fail register: dest_is_existing_file_fail
- name: Stat to make sure the symlink was not created - name: Stat to make sure the symlink was not created
stat: stat:
path: '{{ output_dir }}/file.txt' path: '{{ remote_tmp_dir_test }}/file.txt'
follow: false follow: false
register: dest_is_existing_file_fail_stat register: dest_is_existing_file_fail_stat
- name: Forcefully a symlink with dest already a file - name: Forcefully a symlink with dest already a file
file: file:
src: '{{ output_file }}' src: '{{ output_file }}'
dest: '{{ output_dir }}/file.txt' dest: '{{ remote_tmp_dir_test }}/file.txt'
state: link state: link
force: true force: true
register: dest_is_existing_file_force register: dest_is_existing_file_force
- name: Stat to make sure the symlink was created - name: Stat to make sure the symlink was created
stat: stat:
path: '{{ output_dir }}/file.txt' path: '{{ remote_tmp_dir_test }}/file.txt'
follow: false follow: false
register: dest_is_existing_file_force_stat register: dest_is_existing_file_force_stat

@ -1,10 +1,10 @@
- name: create local file with unicode filename and content - name: create local file with unicode filename and content
lineinfile: lineinfile:
dest: "{{ output_dir }}/语/汉语.txt" dest: "{{ remote_tmp_dir_test }}/语/汉语.txt"
create: true create: true
line: 汉语 line: 汉语
- name: remove local file with unicode filename and content - name: remove local file with unicode filename and content
file: file:
path: "{{ output_dir }}/语/汉语.txt" path: "{{ remote_tmp_dir_test }}/语/汉语.txt"
state: absent state: absent

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

@ -19,7 +19,7 @@
- name: copy an existing file in place - name: copy an existing file in place
copy: copy:
src: existing_known_hosts src: existing_known_hosts
dest: "{{ output_dir }}/known_hosts" dest: "{{ remote_tmp_dir }}/known_hosts"
# test addition # test addition
@ -29,14 +29,14 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: diff register: diff
- name: assert that the diff looks as expected (the key was added at the end) - name: assert that the diff looks as expected (the key was added at the end)
assert: assert:
that: that:
- 'diff is changed' - 'diff is changed'
- 'diff.diff.before_header == diff.diff.after_header == output_dir|expanduser + "/known_hosts"' - 'diff.diff.before_header == diff.diff.after_header == remote_tmp_dir|expanduser + "/known_hosts"'
- 'diff.diff.after.splitlines()[:-1] == diff.diff.before.splitlines()' - 'diff.diff.after.splitlines()[:-1] == diff.diff.before.splitlines()'
- 'diff.diff.after.splitlines()[-1] == example_org_rsa_key.strip()' - 'diff.diff.after.splitlines()[-1] == example_org_rsa_key.strip()'
@ -45,11 +45,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts register: known_hosts
- name: assert that the key was added and ordering preserved - name: assert that the key was added and ordering preserved
@ -68,7 +68,7 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: check register: check
- name: assert that no changes were expected - name: assert that no changes were expected
@ -82,11 +82,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v2 register: known_hosts_v2
- name: assert that no changes happened - name: assert that no changes happened
@ -104,13 +104,13 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: absent state: absent
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: diff register: diff
- name: assert that the diff looks as expected (the key was removed) - name: assert that the diff looks as expected (the key was removed)
assert: assert:
that: that:
- 'diff.diff.before_header == diff.diff.after_header == output_dir|expanduser + "/known_hosts"' - 'diff.diff.before_header == diff.diff.after_header == remote_tmp_dir|expanduser + "/known_hosts"'
- 'diff.diff.before.splitlines()[-1] == example_org_rsa_key.strip()' - 'diff.diff.before.splitlines()[-1] == example_org_rsa_key.strip()'
- 'diff.diff.after.splitlines() == diff.diff.before.splitlines()[:-1]' - 'diff.diff.after.splitlines() == diff.diff.before.splitlines()[:-1]'
@ -119,11 +119,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: absent state: absent
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v3 register: known_hosts_v3
- name: assert that the key was removed and ordering preserved - name: assert that the key was removed and ordering preserved
@ -142,7 +142,7 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: absent state: absent
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: check register: check
- name: assert that no changes were expected - name: assert that no changes were expected
@ -156,11 +156,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: absent state: absent
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v4 register: known_hosts_v4
- name: assert that no changes happened - name: assert that no changes happened
@ -177,12 +177,12 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
hash_host: yes hash_host: yes
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v5 register: known_hosts_v5
- name: assert that the key was added and ordering preserved - name: assert that the key was added and ordering preserved
@ -201,12 +201,12 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
hash_host: yes hash_host: yes
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v6 register: known_hosts_v6
- name: assert that no changes happened - name: assert that no changes happened
@ -223,11 +223,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: absent state: absent
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v7 register: known_hosts_v7
- name: assert that the key was removed and ordering preserved - name: assert that the key was removed and ordering preserved
@ -245,11 +245,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: absent state: absent
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
register: result register: result
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v8 register: known_hosts_v8
- name: assert that no changes happened - name: assert that no changes happened
@ -267,10 +267,10 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v8 register: known_hosts_v8
- name: assert the plaintext host is there - name: assert the plaintext host is there
@ -283,11 +283,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
hash_host: true hash_host: true
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v9 register: known_hosts_v9
- name: assert the hashed host is there - name: assert the hashed host is there
@ -301,10 +301,10 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v10 register: known_hosts_v10
- name: assert the plaintext host is there - name: assert the plaintext host is there
@ -317,7 +317,7 @@
- name: copy an existing file in place - name: copy an existing file in place
copy: copy:
src: existing_known_hosts src: existing_known_hosts
dest: "{{ output_dir }}/known_hosts" dest: "{{ remote_tmp_dir }}/known_hosts"
# Test key changes # Test key changes
@ -326,7 +326,7 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
hash_host: true hash_host: true
- name: change the key of a hashed host - name: change the key of a hashed host
@ -334,11 +334,11 @@
name: example.org name: example.org
key: "{{ example_org_rsa_key.strip()[:-7] + 'RANDOM=' }}" key: "{{ example_org_rsa_key.strip()[:-7] + 'RANDOM=' }}"
state: present state: present
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
hash_host: true hash_host: true
- name: get the file content - name: get the file content
command: "cat {{output_dir}}/known_hosts" command: "cat {{remote_tmp_dir}}/known_hosts"
register: known_hosts_v11 register: known_hosts_v11
- name: assert the change took place and the key got modified - name: assert the change took place and the key got modified
@ -352,7 +352,7 @@
known_hosts: known_hosts:
name: example.org,acme.com name: example.org,acme.com
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
ignore_errors: yes ignore_errors: yes
register: result register: result
@ -366,7 +366,7 @@
known_hosts: known_hosts:
name: example.com name: example.com
key: "{{ example_org_rsa_key }}" key: "{{ example_org_rsa_key }}"
path: "{{output_dir}}/known_hosts" path: "{{remote_tmp_dir}}/known_hosts"
ignore_errors: yes ignore_errors: yes
register: result register: result

Loading…
Cancel
Save