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

Create chroots if they are missing #3

Closed
spanezz opened this issue Mar 15, 2021 · 2 comments
Closed

Create chroots if they are missing #3

spanezz opened this issue Mar 15, 2021 · 2 comments

Comments

@spanezz
Copy link
Contributor

spanezz commented Mar 15, 2021

It would be nice to also have nspawn-runner create the chroots from configuration files if they are missing, so that a new runner can be deployed with a minimal effort, and it will proceed to generate all the images required in a single command.

@spanezz
Copy link
Contributor Author

spanezz commented Mar 15, 2021

One cannot just store arbitrary values in a playbook, as ansible will complain:

ERROR! 'nspawn_chroot_suite' is not a valid attribute for a Play

However, I can store arbitrary key/value pairs in ansible variables

However, ansible provides a chaotic evil amount of places and ways one can set and generate variables. Also ansible, being uncooperative as usual, does not, as far as I know, provide any kind of library that one could use to load a playbook, put together all its pieces and resolve/introspect variables.

However, I could run a modified playbook that prints variable values. But then I'd need a playbook for maintenance and a playbook for variable lookups. Plus, given ansible's inefficiency, I'd like to avoid running a whole playbook just to figure out chroot details.

However, I can sidestep the whole problem, supporting only variables explictly defined in the playbook file itself,
and nowhere else, and explicitly not supporting Jinja2 expansions, and limited to the first record found in the YAML file. That should be something easily implementable with a simple YAML parsing library.

However, there is no YAML parsing library in the Python standard library, and there are two widespread libraries to choose from, with slightly incompatible APIs.

However, I've already shaved that yak before,
so I can "just" do this:

# Import YAML for parsing only. Prefer pyyaml for loading, because it's
# significantly faster
try:
    import yaml

    def yaml_load(file):
        return yaml.load(file, Loader=yaml.CLoader)
except ModuleNotFoundError:
    try:
        import ruamel.yaml

        yaml_loader = ruamel.yaml.YAML(typ="safe", pure=True)

        def yaml_load(file):
            return yaml_loader.load(file)
    except ModuleNotFoundError:
        def yaml_load(file):
            raise NotImplementedError("this feature requires PyYaml or ruamel.yaml")

At this point, I can define a nspawn_runner_chroot_suite variable with the debootstrap suite to use. Over time I also have a place to add more as needs arise, for example to support different chroot creation methods than deboostrap.

Here's an example chroot configuration snippet:

- name: "Basic buster chroot"
  vars:
     nspawn_runner_chroot_suite: buster
  hosts: all
  user: root
  tasks:
     

@spanezz
Copy link
Contributor Author

spanezz commented Mar 15, 2021

This is now done in c727706

@spanezz spanezz closed this as completed Mar 15, 2021
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