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 a guestfs connexion plugin #13612

Closed
wants to merge 1 commit into from
Closed

Conversation

mscherer
Copy link
Contributor

This permit to edit a base image in a similar fashion to packer,
thus permitting for example to customize base image before uploading
them directly to Glance or similar services for openstack, enabling
immutable server deployment.

It can be used like this:

$ cat hosts
fedora_22 ansible_ssh_host=Fedora-Cloud-Base-22-20150521.x86_64.qcow2 ansible_connection=guestfs

$ cat deploy.yml

---
- hosts: fedora_22
  roles:
  - somerole

$ ansible-playbook -i hosts deploy.yml
[....]

For now, it only support local VM with single OS, but it should be trivial
to add support for remote disks and multiple OS.

@bcoca bcoca added the new_plugin This PR includes a new plugin. label Dec 21, 2015
@bcoca bcoca added this to the next milestone Dec 21, 2015
@jimi-c jimi-c modified the milestones: 2.2.0, stable-2.1 Jun 21, 2016

self.guestfs.add_drive_opts(self.disk)

def _find_python(self):
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this use the value of ansible_python_interpreter? There is a mechanism (winrm.py uses it) to pass in some host variables to connection plugins, so this should probably implement that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't knew about set_host_overrides, I will take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, we need autodetection for Fedora and Ubuntu (since they come with python 3 pre installed, so I need to detect them for running raw to install python2). Now, I am not sure how should the plugin react if the user give a explicit python_interpreter, and if we can assume to be installed if given (especially for something like raw module, which should work without python).

In fact, I wonder if I shouldn't also have a wrapper in shell, since you can't use it on freebsd image with the current system of using a python wrapper if python is not installed (which is the case on freebsd among others). And I might need it soon for netbsd images.

Copy link
Member

Choose a reason for hiding this comment

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

connection plugins should not have their own python logic. If distros are using different python/missing python it is up to user to add (plenty of examples with raw and ansible_python_interpreter).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The python detection is used by the connexion plugin for internal matter, ie be able to run the script whose code is in the EXECUTION_SCRIPT constant, which is a wrapper that do encode stdin/stdout as json, because guestfish do not return the 2 streams separate.

This is separate and not related to the fact that ansible also use python. If perl was installed by default everywhere, I would use it, or if I had a good reason to believe that I could write a portable shell script doing the same without losing sanity points, I would do it.

I guess I could replace that part by a script that do execute the binary, dump stdout and stderr in 2 separate file and then get them, but this look more ugly than the current way (albeit more portable). And if I remember correctly, the python detection is needed so I can run raw or the various shell fragment in the first place. I can take a look again, because that code is not so fresh, but I am confident that if I could have avoided that, I would.

Copy link
Member

Choose a reason for hiding this comment

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

this is why we have shell plugins .... but I do agree on the sanity part ...

@mattclay
Copy link
Member

@mscherer: Could you add this to the integration tests? Specifically, add a section to test_connection.inventory for guestfs and then make sure the tests pass by running:

TEST_FLAGS='-l guestfs' make test_connection

@alikins
Copy link
Contributor

alikins commented Jun 21, 2016

Seems to work for me, I was able to point it to a qcow2 image and run ansible playbook against it. I only tested fedora images, so didn't try windows/ntfs/etc.

For now, it only support local VM with single OS, but it should be trivial
to add support for remote disks and multiple OS.

Would this include specifying a (local) libvirt/qemu url? ie, user vs system ?


import os
import os.path
import guestfs
Copy link
Contributor

Choose a reason for hiding this comment

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

You should raise AnsibleError when guestfs python module isn't available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, fixed in the pushed branch

@mscherer mscherer force-pushed the guestfish_pr branch 2 times, most recently from af1d478 to 15521fc Compare July 4, 2016 12:06
@mscherer
Copy link
Contributor Author

mscherer commented Jul 4, 2016

@mattclay I added a first attempt at the test, I am not sure how to run them the correct way (and I rather avoid running disruptive test on my work laptop). It requires to download a cloud image to test, so I guess I should commit that file in git :)

@mscherer
Copy link
Contributor Author

mscherer commented Jul 4, 2016

@alikins Yeah, I think so. It should be able to do all that you can do with guestfs command line.

So we can use http://libguestfs.org/guestfish.1.html#adding-remote-storage for remote disks, and or also a different libvirt url if needed. Of course, people need to make sure that remote VM are shutdown for obvious concurency issue.

I guess we could pass ansible_libvirt_uri variable or something, provided the connexion plugin can access that information (but I didn't dig that direction yet).

@mscherer
Copy link
Contributor Author

mscherer commented Jul 4, 2016

Ok so we could pass more variable using the set_host_overrides system that @jimi-c spoke earlier, but I rather add the features later.

@mattclay
Copy link
Member

mattclay commented Jul 5, 2016

@mscherer No need to include the image in git, just instructions on what is necessary to run the test, as it appears you've already done. If you can run TEST_FLAGS='-l guestfs' make test_connection and have the tests pass, that's all that is needed for testing.

@mscherer
Copy link
Contributor Author

mscherer commented Oct 8, 2016

So I did started to look at it (after Robyn talk on ansible container), and I did it a issue, and I think that's because we have test using UTF 8 string, but the Fedora cloud image I have do not seems to support utf-8.

I will try to dig a bit, but if test requires a less featurefull image than the usual image for testing utf8, that might be a issue.

@mscherer
Copy link
Contributor Author

Ok so I fixed the first issue regarding utf8, now I hit another issue (so still trying to get it merged)

@mscherer mscherer force-pushed the guestfish_pr branch 2 times, most recently from c5ef5ec to 76efc29 Compare October 22, 2016 17:54
@mscherer
Copy link
Contributor Author

So I fixed the issue I had, and the tests are working (and are documented) on my laptop on RHEL 7.

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Dec 13, 2016
@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Dec 24, 2016
This permit to edit a base image in a similar fashion to packer,
thus permitting for example to customize base image before uploading
them directly to Glance or similar services for openstack, enabling
immutable server deployment.

It can be used like this:

    $ cat hosts
    fedora_22 ansible_ssh_host=Fedora-Cloud-Base-22-20150521.x86_64.qcow2 ansible_connection=guestfs

    $ cat deploy.yml
    ---
    - hosts: fedora_22
      roles:
      - somerole

    $ ansible-playbook -i hosts deploy.yml
    [....]

For now, it only support local VM with single OS, but it should be trivial
to add support for remote disks and multiple OS.
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 28, 2016
@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Jan 5, 2017
''' return the filename for the command output '''
return '%s/cmd.out' % self._tmp

def exec_command(self, cmd, in_data=None, sudoable=False):
Copy link
Member

Choose a reason for hiding this comment

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

if not handling become methods update the class variable to indicate this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure to understand. I suspect I need to change sudoable to True rather than False, becuase that seems to be the default everywhere else, but what class variable do I need to update ?

Copy link
Member

Choose a reason for hiding this comment

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

not that, i'm talking about become_methods list class variable.

Copy link
Member

Choose a reason for hiding this comment

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

example that supports all defaults except 'su'

 become_methods = frozenset(C.BECOME_METHODS).difference(('su',))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would need to test if sudo and su work I guess, as I didn't need them (but I can see why it would be required, at least 'su').

Copy link
Member

Choose a reason for hiding this comment

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

su requires a tty, that is why most 'subprocess' plugins don't support it.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. c:plugins/connection labels Jan 6, 2017
@ansibot
Copy link
Contributor

ansibot commented Apr 11, 2017

@mscherer Greetings! Thanks for taking the time to open this pullrequest. In order for the community to handle your pullrequest effectively, we need a bit more information.

Here are the items we could not find in your description:

  • issue type

Please set the description of this pullrequest with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/PULL_REQUEST_TEMPLATE.md

click here for bot help

@ansibot ansibot added needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Apr 11, 2017
@gundalow gundalow modified the milestone: 2.2.0 Apr 13, 2017
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Jun 29, 2017
@ansibot ansibot added plugins/connection test This PR relates to tests. labels Sep 7, 2017
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Nov 18, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 2, 2018
@gundalow gundalow added the pr_day Has been reviewed during a PR review Day label Sep 19, 2019
@gundalow
Copy link
Contributor

@mscherer
Thank you for your PR.
As part of reviewing the backlog of PRs we are looking at PRs older PRs that haven't been updated in a while

Given that:

  • PR has needed a rebase since April June 2017

Therefore I'm going to close this.

If you or anyone else wants to continue with this work then please do feel free to create a fresh PR and @mention the previous reviewers in here.

@gundalow gundalow closed this Sep 19, 2019
@ansible ansible locked and limited conversation to collaborators Oct 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 c:plugins/connection feature This issue/PR relates to a feature request. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_plugin This PR includes a new plugin. plugins/connection pr_day Has been reviewed during a PR review Day stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
No open projects
Testing
Tests In Progress
Development

Successfully merging this pull request may close these issues.

None yet

9 participants