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

Add machine init --run-playbook #25043

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jakecorrenti
Copy link
Member

@jakecorrenti jakecorrenti commented Jan 17, 2025

Allow the user to provide an Ansible playbook file on init which will then be run on first boot.

This is dependent on containers/podman-machine-os#68 and containers/podman-machine-wsl-os#11 getting merged.

Does this PR introduce a user-facing change?

Adds the `--run-playbook` flag to `podman machine init`

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note labels Jan 17, 2025
@jakecorrenti
Copy link
Member Author

cc @baude

@baude
Copy link
Member

baude commented Jan 19, 2025

/approve

Copy link
Contributor

openshift-ci bot commented Jan 19, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: baude, jakecorrenti

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 19, 2025
@Luap99
Copy link
Member

Luap99 commented Jan 20, 2025

Cross linking containers/podman-machine-os#68 (comment)

Here this seems quite limiting in what it would do. AFAICT ansible playbooks can consist of many different files that are included, the directory structure can be complex, see https://docs.ansible.com/ansible/2.8/user_guide/playbooks_best_practices.html#directory-layout

As such I really don't see how this would help many users with complex things that have more than a single file. Would it not be much better to require the user to have ansible installed on the host and run it from there?

@baude
Copy link
Member

baude commented Jan 20, 2025

no, this is quite useful. it can be a single file and in this case, it is perfectly OK to be ... this, in conjunction with something like a podman machine cp and custom ignition files should solve the ongoing complaints from users about customizing machine images when these choose to simply not rebuild their own.

@Luap99
Copy link
Member

Luap99 commented Jan 20, 2025

it can be a single file and in this case, it is perfectly OK to be

Sure it can be a single file. But this restricts the purpose AFAICT and I bet we just get more people asking to allow multiple files and whatever else ansible can do. Thus I am just not sure if it makes sense to go with a design that we cannot easily extend later.

Also isn't this just super racy? We simply start a playbook but never wait for it to be done which means whatever config should be applied may not be ready thus causing hard to diagnose issues. Also unless someone knows to ssh into the machine and knows the unit name they will not be able to get the output in case of failures.

And then this currently says it runs on first boot but the unit would be run on every boot unless I am missing something.

cmd/podman/machine/init.go Outdated Show resolved Hide resolved
docs/source/markdown/podman-machine-init.1.md.in Outdated Show resolved Hide resolved
pkg/machine/e2e/init_test.go Outdated Show resolved Hide resolved
pkg/machine/e2e/init_test.go Outdated Show resolved Hide resolved
pkg/machine/ignition/ignition.go Outdated Show resolved Hide resolved
pkg/machine/shim/host.go Outdated Show resolved Hide resolved
pkg/machine/ignition/ignition.go Outdated Show resolved Hide resolved
pkg/machine/ignition/ignition.go Outdated Show resolved Hide resolved
@jakecorrenti
Copy link
Member Author

What am I missing here? I did make docs and I made sure the new flag was added to the manpage

@l0rd
Copy link
Member

l0rd commented Jan 21, 2025

I think this won't work on Windows when using WSL until we add ansible in the image used in that case.

More generally, with this PR, we are adding an implicit dependency between podman and the machine image: if ansible is not pre-installed in the machine image (i.e., it's a custom one), --run-playbook doesn't work. I don't know how much of a problem custom images are, but Ansible is not a " small " pre-requisite (in terms of size and its dependencies). If customers habitually use custom images, having a custom image guideline that mentions Ansible would be helpful.

Also, playbooks with a local path won't work (as mentioned in the man page). But this can be worked around if paths in the playbook are converted as it's currently done for volumes and additional build contexts.

@baude
Copy link
Member

baude commented Jan 21, 2025

@jakecorrenti please file a PR to add ansible to the machine image.

@jakecorrenti
Copy link
Member Author

I think this won't work on Windows when using WSL until we add ansible in the image used in that case.

I made a PR to fix that: containers/podman-machine-wsl-os#11. I don't have a way to test it, however.

More generally, with this PR, we are adding an implicit dependency between podman and the machine image: if ansible is not pre-installed in the machine image (i.e., it's a custom one), --run-playbook doesn't work. I don't know how much of a problem custom images are, but Ansible is not a " small " pre-requisite (in terms of size and its dependencies). If customers habitually use custom images, having a custom image guideline that mentions Ansible would be helpful.

Would it be enough to add in the manpage that custom images are required to have Ansible added? Or would you rather have something completely separate.

Also, playbooks with a local path won't work (as mentioned in the man page). But this can be worked around if paths in the playbook are converted as it's currently done for volumes and additional build contexts.

@baude
Copy link
Member

baude commented Jan 21, 2025

Would it be enough to add in the manpage that custom images are required to have Ansible added? Or would you rather have something completely separate.

I think something in the man page like that says this requires ansible be present in the image which is default is a fair thing to do.

But more importantly, lets add a statement to --image that basically says we only support the images we provide. wdyt ?

@jakecorrenti
Copy link
Member Author

Would it be enough to add in the manpage that custom images are required to have Ansible added? Or would you rather have something completely separate.

I think something in the man page like that says this requires ansible be present in the image which is default is a fair thing to do.

But more importantly, lets add a statement to --image that basically says we only support the images we provide. wdyt ?

I think that sounds like a good idea

baude added a commit to baude/podman-machine-os that referenced this pull request Jan 21, 2025
add ansible to the machine image so users can execute a playbook once
the machine is booted.  Users have been asking for a way to automaticaly
configure a machine with various options, files (like certificates), and
configuration tweaks.  Ansible is an excellent tool to do this in the
machine.

See also containers/podman#25043

Signed-off-by: Brent Baude <[email protected]>
@jakecorrenti jakecorrenti force-pushed the machine-copy-files branch 3 times, most recently from 0faa4f6 to ade327b Compare January 22, 2025 22:00
Copy link

Cockpit tests failed for commit ade327b. @martinpitt, @jelly, @mvollmer please check.

@jakecorrenti jakecorrenti force-pushed the machine-copy-files branch 3 times, most recently from 7ac57aa to c3966f4 Compare January 27, 2025 13:58
@jakecorrenti jakecorrenti marked this pull request as ready for review January 28, 2025 12:57
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 28, 2025
@jakecorrenti jakecorrenti force-pushed the machine-copy-files branch 2 times, most recently from 2e9313e to 9bbe2af Compare January 28, 2025 13:41
@Luap99
Copy link
Member

Luap99 commented Jan 28, 2025

@jakecorrenti FYI you should rebase and in general try to always rebase on each push to pick up the latest changes such as CI fixes, the machine test timeout was bumped to 45 mins in the meantime which should make it more likely that the test pass.

@jakecorrenti jakecorrenti force-pushed the machine-copy-files branch 2 times, most recently from 76c3620 to a2e4be9 Compare January 30, 2025 14:51
Allow the user to provide an Ansible playbook file on init which will
then be run on boot.

Signed-off-by: Jake Correnti <[email protected]>
Signed-off-by: Brent Baude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. machine release-note v5.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants