Skip to content

Commit 4ff8ce3

Browse files
demonpigShrews
authored andcommitted
Modify volume mount behavior when source does not exist (#1408)
Pass through container volume mounts as-is. ansible-runner will ignore adding the mountpoint to the '-v` argument list if the source path does not exist. Instead it should respect whatever the user is passing to the '--container-volume-mount' option. The exception would be if the user tried to pass a file as the source path; ansible-runner should resolve the file's parent directory. (cherry picked from commit 2989177)
1 parent ab8ca88 commit 4ff8ce3

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/ansible_runner/config/_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,7 @@ def wrap_args_for_containerization(self,
568568
for mapping in self.container_volume_mounts:
569569
volume_mounts = mapping.split(':', 2)
570570
self._ensure_path_safe_to_mount(volume_mounts[0])
571-
labels = None
572-
if len(volume_mounts) == 3:
573-
labels = f":{volume_mounts[2]}"
574-
self._update_volume_mount_paths(new_args, volume_mounts[0], dst_mount_path=volume_mounts[1], labels=labels)
571+
new_args.extend(["-v", mapping])
575572

576573
# Reference the file with list of keys to pass into container
577574
# this file will be written in ansible_runner.runner

test/unit/config/test__base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_container_volume_mounting_with_Z(tmp_path, mocker):
276276
for i, entry in enumerate(new_args):
277277
if entry == '-v':
278278
mount = new_args[i + 1]
279-
if mount.endswith('project_path/:Z'):
279+
if mount.endswith('project_path:Z'):
280280
break
281281
else:
282282
raise Exception(f'Could not find expected mount, args: {new_args}')
@@ -318,7 +318,7 @@ def test_containerization_settings(tmp_path, runtime, mocker):
318318
'--workdir',
319319
'/runner/project',
320320
'-v', f'{str(tmp_path)}/.ssh/:/home/runner/.ssh/',
321-
'-v', f'{str(tmp_path)}/.ssh/:/root/.ssh/',
321+
'-v', f'{str(tmp_path)}/.ssh/:/root/.ssh/'
322322
]
323323

324324
if os.path.exists('/etc/ssh/ssh_known_hosts'):
@@ -330,6 +330,8 @@ def test_containerization_settings(tmp_path, runtime, mocker):
330330
expected_command_start.extend([
331331
'-v', f'{rc.private_data_dir}/artifacts/:/runner/artifacts/:Z',
332332
'-v', f'{rc.private_data_dir}/:/runner/:Z',
333+
'-v', '/host1:/container1',
334+
'-v', 'host2:/container2',
333335
'--env-file', f'{rc.artifact_dir}/env.list',
334336
])
335337

test/unit/config/test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ def test_container_volume_mounting_with_Z(mocker, tmp_path):
684684
for i, entry in enumerate(new_args):
685685
if entry == '-v':
686686
mount = new_args[i + 1]
687-
if mount.endswith(':/tmp/project_path/:Z'):
687+
if mount.endswith(':/tmp/project_path:Z'):
688688
break
689689
else:
690690
raise Exception(f'Could not find expected mount, args: {new_args}')
@@ -728,7 +728,7 @@ def test_containerization_settings(tmp_path, runtime, mocker):
728728

729729
expected_command_start = [runtime, 'run', '--rm', '--tty', '--interactive', '--workdir', '/runner/project'] + \
730730
['-v', f'{rc.private_data_dir}/:/runner/:Z'] + \
731-
['-v', '/host1/:/container1/', '-v', '/host2/:/container2/'] + \
731+
['-v', '/host1:/container1', '-v', '/host2:/container2'] + \
732732
['--env-file', f'{rc.artifact_dir}/env.list'] + \
733733
extra_container_args + \
734734
['--name', 'ansible_runner_foo'] + \

0 commit comments

Comments
 (0)