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

fix: Run ansible with run_user instead of root for distro install_method #5986

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cloudinit/config/cc_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def is_installed(self) -> bool:


class AnsiblePullDistro(AnsiblePull):
def __init__(self, distro: Distro, user: Optional[str]):
super().__init__(distro)
self.run_user = user

def install(self, pkg_name: str):
if not self.is_installed():
self.distro.install_packages([pkg_name])
Expand Down Expand Up @@ -151,7 +155,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
if install_method == "pip":
ansible = AnsiblePullPip(distro, ansible_user)
else:
ansible = AnsiblePullDistro(distro)
ansible = AnsiblePullDistro(distro, ansible_user)
ansible.install(package_name)
ansible.check_deps()
ansible_config = ansible_cfg.get("ansible_config", "")
Expand Down
12 changes: 8 additions & 4 deletions tests/unittests/config/test_cc_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,16 @@ def test_required_keys(self, cfg, exception, mocker):
def test_deps_not_installed(self, m_which):
"""assert exception raised if package not installed"""
with raises(ValueError):
cc_ansible.AnsiblePullDistro(get_cloud().distro).check_deps()
cc_ansible.AnsiblePullDistro(
get_cloud().distro, "root"
).check_deps()

@mock.patch(M_PATH + "subp.which", return_value=True)
def test_deps(self, m_which):
"""assert exception not raised if package installed"""
cc_ansible.AnsiblePullDistro(get_cloud().distro).check_deps()
cc_ansible.AnsiblePullDistro(
get_cloud().distro, "ansible"
).check_deps()

@mark.serial
@mock.patch(M_PATH + "subp.subp", return_value=("stdout", "stderr"))
Expand Down Expand Up @@ -390,7 +394,7 @@ def test_ansible_pull(self, m_subp1, m_subp2, m_which, cfg, expected):
ansible_pull = (
cc_ansible.AnsiblePullPip(distro, "ansible")
if pull_type == "pip"
else cc_ansible.AnsiblePullDistro(distro)
else cc_ansible.AnsiblePullDistro(distro, "")
)
cc_ansible.run_ansible_pull(
ansible_pull, deepcopy(cfg["ansible"]["pull"])
Expand All @@ -415,7 +419,7 @@ def test_do_not_run(self, m_validate):
def test_parse_version_distro(self, m_subp):
"""Verify that the expected version is returned"""
assert cc_ansible.AnsiblePullDistro(
get_cloud().distro
get_cloud().distro, ""
).get_version() == lifecycle.Version(2, 10, 8)

@mock.patch("cloudinit.subp.subp", side_effect=[(pip_version, "")])
Expand Down
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ sbraz
scorpion44
SeanSith
shaardie
shaerpour
shell-skrimp
shi2wei3
ShPakvel
Expand Down