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

incus_connection: Allow non-root users to connect to an instance #9743

Merged

Conversation

yeetypete
Copy link
Contributor

SUMMARY

Currently the incus connection only supports connecting to an instance as root. This PR extends the plugin to allow a non-root user, configurable via the ansible_user var to connect to the instance. The option incus_become_method controls the command used to switch users, (su by default but could also be sudo -u). The defaults ensure the old behavior so this should be a non-breaking change.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

incus_connection

ADDITIONAL INFORMATION

Replicates functionality from #9659 for the incus plugin

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added WIP Work in progress connection connection plugin feature This issue/PR relates to a feature request needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI new_contributor Help guide this first time contributor plugins plugin (any type) labels Feb 14, 2025
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-10 Automatically create a backport for the stable-10 branch labels Feb 14, 2025
@ansibullbot ansibullbot removed the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI label Feb 14, 2025
@yeetypete yeetypete marked this pull request as ready for review February 15, 2025 11:17
@yeetypete
Copy link
Contributor Author

yeetypete commented Feb 15, 2025

Can be tested with:

- name: Create an incus container
  hosts: localhost
  gather_facts: true
  tasks:
    - name: Create a container
      community.general.lxd_container:
        name: "jammy"
        state: started
        url: "unix:/var/lib/incus/unix.socket"
        source:
          type: image
          mode: pull
          server: "https://images.linuxcontainers.org/"
          protocol: simplestreams
          alias: "ubuntu/jammy/cloud"
        wait_for_container: true
        wait_for_ipv4_addresses: true

    - name: Add the container to the inventory
      ansible.builtin.add_host:
        name: "jammy"
        groups:
          - incus
        ansible_connection: community.general.incus
        ansible_user: ubuntu

- name: Run tasks in the container
  hosts: incus
  gather_facts: true
  tasks:
    - name: Create a file in the container
      ansible.builtin.copy:
        content: "Hello World!\n"
        dest: "{{ ansible_env.HOME }}/hello.txt"

Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an Ansible perspective, looks OK.

@ansibullbot ansibullbot removed the new_contributor Help guide this first time contributor label Feb 16, 2025
@stgraber
Copy link
Contributor

LGTM

@felixfontein felixfontein merged commit 94e1511 into ansible-collections:main Feb 17, 2025
138 checks passed
Copy link

patchback bot commented Feb 17, 2025

Backport to stable-10: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-10/94e1511005e621f56002f3b057d03b46f7639fb3/pr-9743

Backported as #9765

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein felixfontein removed backport-10 Automatically create a backport for the stable-10 branch check-before-release PR will be looked at again shortly before release and merged if possible. labels Feb 17, 2025
patchback bot pushed a commit that referenced this pull request Feb 17, 2025
* feat: add remote_user option to incus connection

* feat: add changelog fragment

* fix: formatting

(cherry picked from commit 94e1511)
@felixfontein
Copy link
Collaborator

@yeetypete thanks for your contribution!
@stgraber thanks for reviewing!

felixfontein pushed a commit that referenced this pull request Feb 17, 2025
…oot users to connect to an instance (#9765)

incus_connection: Allow non-root users to connect to an instance (#9743)

* feat: add remote_user option to incus connection

* feat: add changelog fragment

* fix: formatting

(cherry picked from commit 94e1511)

Co-authored-by: Peter Siegel <[email protected]>
rt-vnx pushed a commit to rt-vnx/community.general that referenced this pull request Feb 20, 2025
…ible-collections#9743)

* feat: add remote_user option to incus connection

* feat: add changelog fragment

* fix: formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
connection connection plugin feature This issue/PR relates to a feature request plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants