Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronize.py loses sudo on retries #503

Open
jnm27 opened this issue Oct 20, 2023 · 0 comments
Open

synchronize.py loses sudo on retries #503

jnm27 opened this issue Oct 20, 2023 · 0 comments

Comments

@jnm27
Copy link

jnm27 commented Oct 20, 2023

SUMMARY

When using the synchronize module in an until: loop, the first attempt will have --rsync-path set correctly to add sudo, but subsequent retries will not have sudo, it omits the --rsync-path argument entirely.

I believe this is due to the code in the synchronize.py action module which reads play_context.become and sets the rsync_path appropriately, but then sets play_context.become to False. I think Ansible is not re-setting the play_context on retries, so it continues to be False.

        if not dest_is_local:
            # don't escalate for docker. doing --rsync-path with docker exec fails
            # and we can switch directly to the user via docker arguments
            if self._play_context.become and not rsync_path and self._remote_transport not in DOCKER + PODMAN:
                # If no rsync_path is set, become was originally set, and dest is
                # remote then add privilege escalation here.
                if self._play_context.become_method == 'sudo':
                    if self._play_context.become_user:
                        rsync_path = 'sudo -u %s rsync' % self._play_context.become_user
                    else:
                        rsync_path = 'sudo rsync'
                # TODO: have to add in the rest of the become methods here

            # We cannot use privilege escalation on the machine running the
            # module.  Instead we run it on the machine rsync is connecting
            # to.
            self._play_context.become = False

The workaround is to explicitly specify "rsync_path: sudo rsync" in the task, instead of letting the synchronize module default it.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

synchronize.py

ANSIBLE VERSION
ansible [core 2.15.0]
COLLECTION VERSION
1.5.4
CONFIGURATION
N/A
OS / ENVIRONMENT

RHEL8

STEPS TO REPRODUCE
Use the synchronize module, do not specify the rsync_path, and specify until: with at least 1 retry.
Make the synchronize fail the first time, and enter the retry. View the -vvvvv output to see that the first attempt has rsync_path defined with sudo, but the second attempt does not.
EXPECTED RESULTS

synchronize sets rsync_path on retries to sudo

ACTUAL RESULTS

synchronize does not set rsync_path on retries to sudo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant