Get copy tests passing with split controller/target (#58516)
* Get copy tests passing with split controller/target * Remove sudoers file * add missed set_fact
This commit is contained in:
parent
16d6fcf514
commit
737dbefd78
5 changed files with 52 additions and 21 deletions
|
@ -273,8 +273,8 @@ class DataLoader:
|
||||||
:returns: An absolute path to the filename ``source`` if found
|
:returns: An absolute path to the filename ``source`` if found
|
||||||
:raises: An AnsibleFileNotFound Exception if the file is found to exist in the search paths
|
:raises: An AnsibleFileNotFound Exception if the file is found to exist in the search paths
|
||||||
'''
|
'''
|
||||||
b_dirname = to_bytes(dirname)
|
b_dirname = to_bytes(dirname, errors='surrogate_or_strict')
|
||||||
b_source = to_bytes(source)
|
b_source = to_bytes(source, errors='surrogate_or_strict')
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
search = []
|
search = []
|
||||||
|
@ -305,8 +305,8 @@ class DataLoader:
|
||||||
# always append basedir as last resort
|
# always append basedir as last resort
|
||||||
# don't add dirname if user already is using it in source
|
# don't add dirname if user already is using it in source
|
||||||
if b_source.split(b'/')[0] != dirname:
|
if b_source.split(b'/')[0] != dirname:
|
||||||
search.append(os.path.join(to_bytes(self.get_basedir()), b_dirname, b_source))
|
search.append(os.path.join(to_bytes(self.get_basedir(), errors='surrogate_or_strict'), b_dirname, b_source))
|
||||||
search.append(os.path.join(to_bytes(self.get_basedir()), b_source))
|
search.append(os.path.join(to_bytes(self.get_basedir(), errors='surrogate_or_strict'), b_source))
|
||||||
|
|
||||||
display.debug(u'search_path:\n\t%s' % to_text(b'\n\t'.join(search)))
|
display.debug(u'search_path:\n\t%s' % to_text(b'\n\t'.join(search)))
|
||||||
for b_candidate in search:
|
for b_candidate in search:
|
||||||
|
@ -316,7 +316,7 @@ class DataLoader:
|
||||||
break
|
break
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
raise AnsibleFileNotFound(file_name=source, paths=[to_text(p) for p in search])
|
raise AnsibleFileNotFound(file_name=source, paths=[to_native(p) for p in search])
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -44,20 +44,22 @@ def unfrackpath(path, follow=True, basedir=None):
|
||||||
'$HOME/../../var/mail' becomes '/var/spool/mail'
|
'$HOME/../../var/mail' becomes '/var/spool/mail'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if basedir is None:
|
b_basedir = to_bytes(basedir, errors='surrogate_or_strict', nonstring='passthru')
|
||||||
basedir = os.getcwd()
|
|
||||||
elif os.path.isfile(to_bytes(basedir, errors='surrogate_or_strict')):
|
|
||||||
basedir = os.path.dirname(basedir)
|
|
||||||
|
|
||||||
final_path = os.path.expanduser(os.path.expandvars(to_bytes(path, errors='surrogate_or_strict')))
|
if b_basedir is None:
|
||||||
|
b_basedir = to_bytes(os.getcwd(), errors='surrogate_or_strict')
|
||||||
|
elif os.path.isfile(b_basedir):
|
||||||
|
b_basedir = os.path.dirname(b_basedir)
|
||||||
|
|
||||||
if not os.path.isabs(final_path):
|
b_final_path = os.path.expanduser(os.path.expandvars(to_bytes(path, errors='surrogate_or_strict')))
|
||||||
final_path = os.path.join(to_bytes(basedir, errors='surrogate_or_strict'), final_path)
|
|
||||||
|
if not os.path.isabs(b_final_path):
|
||||||
|
b_final_path = os.path.join(b_basedir, b_final_path)
|
||||||
|
|
||||||
if follow:
|
if follow:
|
||||||
final_path = os.path.realpath(final_path)
|
b_final_path = os.path.realpath(b_final_path)
|
||||||
|
|
||||||
return to_text(os.path.normpath(final_path), errors='surrogate_or_strict')
|
return to_text(os.path.normpath(b_final_path), errors='surrogate_or_strict')
|
||||||
|
|
||||||
|
|
||||||
def makedirs_safe(path, mode=None):
|
def makedirs_safe(path, mode=None):
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
needs/root
|
needs/root
|
||||||
shippable/posix/group2
|
shippable/posix/group2
|
||||||
|
destructive
|
||||||
|
|
|
@ -34,6 +34,20 @@
|
||||||
name: '{{ remote_unprivileged_user }}'
|
name: '{{ remote_unprivileged_user }}'
|
||||||
register: user
|
register: user
|
||||||
|
|
||||||
|
- name: Check sudoers dir
|
||||||
|
stat:
|
||||||
|
path: /etc/sudoers.d
|
||||||
|
register: etc_sudoers
|
||||||
|
|
||||||
|
- name: Set sudoers.d path fact
|
||||||
|
set_fact:
|
||||||
|
sudoers_d_file: "{{ '/etc/sudoers.d' if etc_sudoers.stat.exists else '/usr/local/etc/sudoers.d' }}/{{ remote_unprivileged_user }}"
|
||||||
|
|
||||||
|
- name: Create sudoers file
|
||||||
|
copy:
|
||||||
|
dest: "{{ sudoers_d_file }}"
|
||||||
|
content: "{{ remote_unprivileged_user }} ALL=(ALL) NOPASSWD: ALL"
|
||||||
|
|
||||||
- file:
|
- file:
|
||||||
path: "{{ user.home }}/.ssh"
|
path: "{{ user.home }}/.ssh"
|
||||||
owner: '{{ remote_unprivileged_user }}'
|
owner: '{{ remote_unprivileged_user }}'
|
||||||
|
@ -93,3 +107,8 @@
|
||||||
name: '{{ remote_unprivileged_user }}'
|
name: '{{ remote_unprivileged_user }}'
|
||||||
state: absent
|
state: absent
|
||||||
remove: yes
|
remove: yes
|
||||||
|
|
||||||
|
- name: Remove sudoers.d file
|
||||||
|
file:
|
||||||
|
path: "{{ sudoers_d_file }}"
|
||||||
|
state: absent
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
- copy_result.dest == remote_file_expanded
|
- copy_result.dest == remote_file_expanded
|
||||||
- "'group' in copy_result"
|
- "'group' in copy_result"
|
||||||
- "'gid' in copy_result"
|
- "'gid' in copy_result"
|
||||||
- "'md5sum' in copy_result"
|
|
||||||
- "'checksum' in copy_result"
|
- "'checksum' in copy_result"
|
||||||
- "'owner' in copy_result"
|
- "'owner' in copy_result"
|
||||||
- "'size' in copy_result"
|
- "'size' in copy_result"
|
||||||
|
@ -1068,16 +1067,19 @@
|
||||||
file:
|
file:
|
||||||
path: 'source_recursive'
|
path: 'source_recursive'
|
||||||
state: directory
|
state: directory
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Create a file inside of the directory
|
- name: Create a file inside of the directory
|
||||||
copy:
|
copy:
|
||||||
content: "testing"
|
content: "testing"
|
||||||
dest: 'source_recursive/file'
|
dest: 'source_recursive/file'
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Create a directory to place the test output in
|
- name: Create a directory to place the test output in
|
||||||
file:
|
file:
|
||||||
path: 'destination'
|
path: 'destination'
|
||||||
state: directory
|
state: directory
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Copy the directory and files within (no trailing slash)
|
- name: Copy the directory and files within (no trailing slash)
|
||||||
copy:
|
copy:
|
||||||
|
@ -1323,9 +1325,10 @@
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "file_attrs.stat.uid == 0"
|
|
||||||
- "file_attrs.stat.pw_name == 'root'"
|
|
||||||
- "file_attrs.stat.mode == '0604'"
|
- "file_attrs.stat.mode == '0604'"
|
||||||
|
# The below assertions make an invalid assumption, these were not explicitly set
|
||||||
|
# - "file_attrs.stat.uid == 0"
|
||||||
|
# - "file_attrs.stat.pw_name == 'root'"
|
||||||
|
|
||||||
- name: check that the containing directory did not change attributes
|
- name: check that the containing directory did not change attributes
|
||||||
stat: path={{ remote_dir }}/directory/
|
stat: path={{ remote_dir }}/directory/
|
||||||
|
@ -1343,7 +1346,8 @@
|
||||||
#
|
#
|
||||||
# Recursive copying with symlinks tests
|
# Recursive copying with symlinks tests
|
||||||
#
|
#
|
||||||
- block:
|
- delegate_to: localhost
|
||||||
|
block:
|
||||||
- name: Create a test dir to copy
|
- name: Create a test dir to copy
|
||||||
file:
|
file:
|
||||||
path: '{{ local_temp_dir }}/top_dir'
|
path: '{{ local_temp_dir }}/top_dir'
|
||||||
|
@ -1376,7 +1380,6 @@
|
||||||
path: '{{ local_temp_dir }}/top_dir/subdir/circle'
|
path: '{{ local_temp_dir }}/top_dir/subdir/circle'
|
||||||
src: '{{ local_temp_dir }}/top_dir/'
|
src: '{{ local_temp_dir }}/top_dir/'
|
||||||
state: link
|
state: link
|
||||||
delegate_to: localhost
|
|
||||||
|
|
||||||
- name: Copy the directory's link
|
- name: Copy the directory's link
|
||||||
copy:
|
copy:
|
||||||
|
@ -1936,22 +1939,26 @@
|
||||||
user:
|
user:
|
||||||
name: '{{ ansible_copy_test_user_name }}'
|
name: '{{ ansible_copy_test_user_name }}'
|
||||||
state: present
|
state: present
|
||||||
|
become: true
|
||||||
register: ansible_copy_test_user
|
register: ansible_copy_test_user
|
||||||
|
|
||||||
- name: execute - create a group for test
|
- name: execute - create a group for test
|
||||||
group:
|
group:
|
||||||
name: '{{ ansible_copy_test_user_name }}'
|
name: '{{ ansible_copy_test_user_name }}'
|
||||||
state: present
|
state: present
|
||||||
|
become: true
|
||||||
register: ansible_copy_test_group
|
register: ansible_copy_test_group
|
||||||
|
|
||||||
- name: execute - Copy the directory on remote with chown
|
- name: execute - Copy the directory on remote with chown
|
||||||
copy:
|
copy:
|
||||||
remote_src: True
|
remote_src: True
|
||||||
src: '{{ remote_dir }}/remote_dir_src/'
|
src: '{{ remote_dir_expanded }}/remote_dir_src/'
|
||||||
dest: '{{ remote_dir }}/new_dir_with_chown'
|
dest: '{{ remote_dir_expanded }}/new_dir_with_chown'
|
||||||
owner: '{{ ansible_copy_test_user_name }}'
|
owner: '{{ ansible_copy_test_user_name }}'
|
||||||
group: '{{ ansible_copy_test_user_name }}'
|
group: '{{ ansible_copy_test_user_name }}'
|
||||||
|
follow: true
|
||||||
register: testcase5
|
register: testcase5
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: gather - Stat the new_dir_with_chown
|
- name: gather - Stat the new_dir_with_chown
|
||||||
stat:
|
stat:
|
||||||
|
@ -2009,11 +2016,13 @@
|
||||||
name: '{{ ansible_copy_test_user_name }}'
|
name: '{{ ansible_copy_test_user_name }}'
|
||||||
state: absent
|
state: absent
|
||||||
remove: yes
|
remove: yes
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: execute - remove the group for test
|
- name: execute - remove the group for test
|
||||||
group:
|
group:
|
||||||
name: '{{ ansible_copy_test_user_name }}'
|
name: '{{ ansible_copy_test_user_name }}'
|
||||||
state: absent
|
state: absent
|
||||||
|
become: true
|
||||||
|
|
||||||
## testcase last - make sure remote_dir_src not change
|
## testcase last - make sure remote_dir_src not change
|
||||||
- block:
|
- block:
|
||||||
|
|
Loading…
Reference in a new issue