Salt example: Clone new fedora vm into specialized templates revisions

Go back to topic: Salt example: Clone new fedora vm into specialized templates

  1. v3 anchor; v3 full version
  2. v2 anchor; v2 full version

Revision #3

Edited on
2023-09-07
Edited by user
deeplow

Revision #2

Edited on
2023-05-19
Edited by user
gust
This is the top-level shell script that runs all the salt sls files. Obviously you can extract the individual commands after `else` if you want to develop your own custom solution iteratively. This is the top-level shell script that runs all the salt sls files. Obviously you can extract the individual commands after `else` if you want to develop your own custom solution iteratively. I call this file with one argument, the number of the fedora version I am customizing, e.g. `fedora-multiply.sh 37`.
You will notice some commands have `--skip-dom0 --targets=fedora-...`. These are dispatched from dom0 to run their sls files on the VMs listed under `--targets=`. The commands that do not use these flags run theirsls files only on `dom0`. Also, some commands have a pillar passed in as a JSON object with the key "fedorav". This is the fedora version and is used to render jinja templates in the sls files that name and identify the templateVMs. Below are the sls files. You will notice some commands have `--skip-dom0 --targets=fedora-...`. These are dispatched from dom0 to run their SLS files on the VMs listed under `--targets=`. The commands that do not use these flags run their SLS files only on `dom0`. Also, some commands have a pillar passed in as a JSON object with the key "fedorav". This is the fedora version and is used to render jinja templates in the SLS files that name and identify the templateVMs. Below are the SLS files.
This one clones `fedora-XX- to `fedora-XX-general` and copies the open source IBM Plex font out of `dom0` into the `fedora-XX-general` template as well, since I like that font :-) This one clones `fedora-XX` to `fedora-XX-general` and copies the open source IBM Plex font out of `dom0` into the `fedora-XX-general` template as well, since I like that font :-) Note the first use of jinja templates, using the key/value ("fedorav": "37") we passed in on the command line (in `/home/user/bin/fedora-multiply.sh`) as a JSON object.
#!/usr/bin/bash set -e #quit on error if [ -z "$1" ] then echo "USAGE: fedora-multiply FVERSION" else sudo qubesctl state.apply fedora-clone-to-general pillar="{\"fedorav\": \"$1\"}" sudo qubesctl --skip-dom0 --targets=fedora-$1-general state.apply fedora-general-configure sudo qubesctl state.apply fedora-general-multiply pillar="{\"fedorav\": \"$1\"}" sudo qubesctl --skip-dom0 --targets=fedora-$1-media state.apply fedora-media-configure fi fedora-clone-to-general: qvm.clone: - source: fedora-{{ pillar['fedorav'] }} - name: fedora-{{ pillar['fedorav'] }}-general plex-to-fedora-general: cmd.run: - name: qvm-copy-to-vm fedora-{{ pillar['fedorav'] }}-general /home/user/Plex
Cloning `fedora-XX-general` into specialized templates like `fedora-XX-print`, `fedora-XX-media`, etc: Cloning `fedora-XX-general` into specialized templates like `fedora-XX-print`, `fedora-XX-media`, etc. Notice this first shuts down `fedora-XX-general` so that its new configuration is saved before it is cloned:
In my last example [tutorial](https://forum.qubes-os.org/t/using-salt-to-install-packages-in-template-vm-simple-example/13345) I used top files alongside sls files. The purpose of top files is to map sls files to particular machines. I find it easier to simply do these mappings by customizing my call to `qubesctl` with an explicit `--targets=...` command (with `--skip-dom0` if needed) and then calling a particular sls file via `state.apply`. I believe @unman suggested this approach in his reply to my last example tutorial. If you do try and use top files, be aware that each target in the top file can target one or more VMs but *will still be run on dom0* regardless of whether this matches the target specification. You need to pass `--skip-dom0` to thwart this behavior.In my last example [tutorial](https://forum.qubes-os.org/t/using-salt-to-install-packages-in-template-vm-simple-example/13345) I used top files alongside SLS files. The purpose of top files is to map SLS files to particular machines. I find it easier to simply do these mappings by customizing my call to `qubesctl` with an explicit `--targets=...` command (with `--skip-dom0` if needed) and then calling a particular SLS file via `state.apply`. I believe @unman suggested this approach in his reply to my last example tutorial. If you do try and use top files, be aware that each target in the top file can target one or more VMs but *will still be run on dom0* regardless of whether this matches the target specification. You need to pass `--skip-dom0` to thwart this behavior.