mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
parent
f1386bb114
commit
1ec8b6e3c5
5 changed files with 57 additions and 1 deletions
|
@ -1196,8 +1196,16 @@ class Runner(object):
|
||||||
''' takes a remote path and performs tilde expansion on the remote host '''
|
''' takes a remote path and performs tilde expansion on the remote host '''
|
||||||
if not path.startswith('~'):
|
if not path.startswith('~'):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
split_path = path.split(os.path.sep, 1)
|
split_path = path.split(os.path.sep, 1)
|
||||||
cmd = conn.shell.expand_user(split_path[0])
|
expand_path = split_path[0]
|
||||||
|
if expand_path == '~':
|
||||||
|
if self.sudo and self.sudo_user:
|
||||||
|
expand_path = '~%s' % self.sudo_user
|
||||||
|
elif self.su and self.su_user:
|
||||||
|
expand_path = '~%s' % self.su_user
|
||||||
|
|
||||||
|
cmd = conn.shell.expand_user(expand_path)
|
||||||
data = self._low_level_exec_command(conn, cmd, tmp, sudoable=False, su=False)
|
data = self._low_level_exec_command(conn, cmd, tmp, sudoable=False, su=False)
|
||||||
initial_fragment = utils.last_non_blank_line(data['stdout'])
|
initial_fragment = utils.last_non_blank_line(data['stdout'])
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
- hosts: testhost
|
- hosts: testhost
|
||||||
gather_facts: True
|
gather_facts: True
|
||||||
roles:
|
roles:
|
||||||
|
# In destructive because it creates and removes a user
|
||||||
|
- { role: test_sudo, tags: test_sudo}
|
||||||
- { role: test_service, tags: test_service }
|
- { role: test_service, tags: test_service }
|
||||||
# Current pip unconditionally uses md5. We can re-enable if pip switches
|
# Current pip unconditionally uses md5. We can re-enable if pip switches
|
||||||
# to a different hash or allows us to not check md5
|
# to a different hash or allows us to not check md5
|
||||||
|
|
44
test/integration/roles/test_sudo/tasks/main.yml
Normal file
44
test/integration/roles/test_sudo/tasks/main.yml
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
- include_vars: default.yml
|
||||||
|
|
||||||
|
- name: Create test user
|
||||||
|
user:
|
||||||
|
name: "{{ sudo_test_user }}"
|
||||||
|
|
||||||
|
- name: tilde expansion honors sudo in file
|
||||||
|
sudo: True
|
||||||
|
sudo_user: "{{ sudo_test_user }}"
|
||||||
|
file:
|
||||||
|
path: "~/foo.txt"
|
||||||
|
state: touch
|
||||||
|
|
||||||
|
- name: check that the path in the user's home dir was created
|
||||||
|
stat:
|
||||||
|
path: "~{{ sudo_test_user }}/foo.txt"
|
||||||
|
register: results
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "results.stat.exists == True"
|
||||||
|
|
||||||
|
- name: tilde expansion honors sudo in template
|
||||||
|
sudo: True
|
||||||
|
sudo_user: "{{ sudo_test_user }}"
|
||||||
|
template:
|
||||||
|
src: "bar.j2"
|
||||||
|
dest: "~/bar.txt"
|
||||||
|
|
||||||
|
- name: check that the path in the user's home dir was created
|
||||||
|
stat:
|
||||||
|
path: "~{{ sudo_test_user }}/bar.txt"
|
||||||
|
register: results
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "results.stat.exists == True"
|
||||||
|
|
||||||
|
- name: Remove test user and their home dir
|
||||||
|
user:
|
||||||
|
name: "{{ sudo_test_user }}"
|
||||||
|
state: "absent"
|
||||||
|
remove: "yes"
|
||||||
|
|
1
test/integration/roles/test_sudo/templates/bar.j2
Normal file
1
test/integration/roles/test_sudo/templates/bar.j2
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{ sudo_test_user }}
|
1
test/integration/roles/test_sudo/vars/default.yml
Normal file
1
test/integration/roles/test_sudo/vars/default.yml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
sudo_test_user: ansibletest1
|
Loading…
Add table
Add a link
Reference in a new issue