diff options
author | Jasper Ras <jras@hostnet.nl> | 2025-01-19 21:14:51 +0100 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2025-01-19 21:14:51 +0100 |
commit | 9642cd7ae24f0ba79ce5647c709b35ae8f06a285 (patch) | |
tree | ae25c3b0db7ae4c23186b294c6d000073f085c2d /3 Resources | |
parent | 969b96c2531fb986f6c7f21fd544391b439defd7 (diff) |
vault backup: 2025-01-19 21:14:51
Diffstat (limited to '3 Resources')
76 files changed, 984 insertions, 0 deletions
diff --git a/3 Resources/.gitkeep b/3 Resources/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/3 Resources/.gitkeep diff --git a/3 Resources/Bash.md b/3 Resources/Bash.md new file mode 100644 index 0000000..841443f --- /dev/null +++ b/3 Resources/Bash.md @@ -0,0 +1 @@ +How to [[Reference arguments]].
\ No newline at end of file diff --git a/3 Resources/Bash/Reference arguments.md b/3 Resources/Bash/Reference arguments.md new file mode 100644 index 0000000..f39eeb1 --- /dev/null +++ b/3 Resources/Bash/Reference arguments.md @@ -0,0 +1,6 @@ +Reference as array: `$@`. +Reference as string: `$*`. + +Let's say we want to open a file in our favorite editor through a script, prefixing the filename with something such as a date. +If we were to use `hx "$(date) $@"`, where we reference the arguments as an array, it'd open more than one file - one for the date and one for each argument. +We must use `$*` so that our invocation becomes `hx "$(date) $*"`. This would open a single file with the name being the combination of our arguments prefixed by date.
\ No newline at end of file diff --git a/3 Resources/CSS.md b/3 Resources/CSS.md new file mode 100644 index 0000000..32a3113 --- /dev/null +++ b/3 Resources/CSS.md @@ -0,0 +1,28 @@ +**Display** +display none vs visibility hidden: display: none is really like the element does not exist. Visibility hidden just hides it but it still takes space. + +A display: none element can still have size and be coloured with a background image. It still doesn't take space. This can be used for a timeline bar for example! + +**Flexbox** +Flexbox deals with layout always in only one dimension; it's possible to specify which dimension: either vertical or horizontal. + +Two axes: main and cross + +Control main axis: `flex-direction: row|row-reverse|column|column-reverse`. The first two make it a horizontal layout and the latter make it a vertical layout. + +Cross axis is always the opposite of `flex-direction`, so if `flex-direction: row-reverse` the cross axis is `column-reverse`. + +The writing mode determines where the start and end are, based on for example languages. Japanese is written from right-to-left rather than western left-to-right. +So while in Europe the start of a flexbox is at the left and the end at the right in Japan this would be reversed. + +**Relationships** +An important aspect of creating layouts with CSS is the relationships of elements with each other. For example parent/child relationships. + +If we change the width of a parent element; the height of all children increase. This happens because the total area of the parent remains the same. + +When the edge of a child aligns with its parent and we add a margin to the child; it pushes to the parent as well. This phenomenon is called ==collapsing margins==. It can be prevented by unaligning the edge(s) for example by adding padding or setting `display: flow-root;`. + +In `flexbox` siblings push against each other; if we add padding to one, it pushes against the other making it smaller. This does not happen in grid, where each cell gets a fixed size and the padding pushes against its own side. + +**Centering stuff** +Use `margin-inline: auto;` -> this adds margins on both sides of the element. This can be used to center stuff on the page for example.
\ No newline at end of file diff --git a/3 Resources/Gitlab/References.md b/3 Resources/Gitlab/References.md new file mode 100644 index 0000000..1c0e61a --- /dev/null +++ b/3 Resources/Gitlab/References.md @@ -0,0 +1,6 @@ +--- +tags: + - reference + - gitlab +--- +- https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
\ No newline at end of file diff --git a/3 Resources/HTML/Inline VS Block elements.md b/3 Resources/HTML/Inline VS Block elements.md new file mode 100644 index 0000000..bd72478 --- /dev/null +++ b/3 Resources/HTML/Inline VS Block elements.md @@ -0,0 +1,69 @@ +A block element always starts on a new line and automatically have their margin set to a non-zero value. +An inline element, as the name suggests, does not start on a new line and has no automatic margins. It +takes only the space that is required for the content it contains. + +Block elements: +- <address> +- <article> +- <aside> +- <blockquote> +- <canvas> +- <dd> +- <div> +- <dl> +- <dt> +- <fieldset> +- <figcaption> +- <figure> +- <footer> +- <form> +- <h1>-<h6> +- <header> +- <hr> +- <li> +- <main> +- <nav> +- <noscript> +- <ol> +- <p> +- <pre> +- <section> +- <table> +- <tfoot> +- <ul> +- <video> + +Inline elements: +- <a> +- <abbr> +- <acronym> +- <b> +- <bdo> +- <big> +- <br> +- <button> +- <cite> +- <code> +- <dfn> +- <em> +- <i> +- <img> +- <input> +- <kbd> +- <label> +- <map> +- <object> +- <output> +- <q> +- <samp> +- <script> +- <select> +- <small> +- <span> +- <strong> +- <sub> +- <sup> +- <textarea> +- <time> +- <tt> +- <var> diff --git a/3 Resources/Helix/Inline diagnostics.md b/3 Resources/Helix/Inline diagnostics.md new file mode 100644 index 0000000..2a84825 --- /dev/null +++ b/3 Resources/Helix/Inline diagnostics.md @@ -0,0 +1,13 @@ +#helix #editor + + +completion supports paths (filepaths etc). +snippet completion from LSP supported +inline diagnostics can be enabled with: +``` +[editor] +end-of-line-diagnostics = "hint"; + +[editor.inline-diagnostics] +cursor-line = "error"; +```
\ No newline at end of file diff --git a/3 Resources/Images/IMG_3980.jpg b/3 Resources/Images/IMG_3980.jpg Binary files differnew file mode 100644 index 0000000..93dac36 --- /dev/null +++ b/3 Resources/Images/IMG_3980.jpg diff --git a/3 Resources/Images/IMG_3981.jpg b/3 Resources/Images/IMG_3981.jpg Binary files differnew file mode 100644 index 0000000..bea7875 --- /dev/null +++ b/3 Resources/Images/IMG_3981.jpg diff --git a/3 Resources/Images/IMG_3982.jpg b/3 Resources/Images/IMG_3982.jpg Binary files differnew file mode 100644 index 0000000..8697dc4 --- /dev/null +++ b/3 Resources/Images/IMG_3982.jpg diff --git a/3 Resources/Images/IMG_3985.jpg b/3 Resources/Images/IMG_3985.jpg Binary files differnew file mode 100644 index 0000000..e78dec5 --- /dev/null +++ b/3 Resources/Images/IMG_3985.jpg diff --git a/3 Resources/Images/IMG_3987.jpg b/3 Resources/Images/IMG_3987.jpg Binary files differnew file mode 100644 index 0000000..da257d5 --- /dev/null +++ b/3 Resources/Images/IMG_3987.jpg diff --git a/3 Resources/Images/Pasted image 20250107205518.jpg b/3 Resources/Images/Pasted image 20250107205518.jpg Binary files differnew file mode 100644 index 0000000..bea7875 --- /dev/null +++ b/3 Resources/Images/Pasted image 20250107205518.jpg diff --git a/3 Resources/Linux/APT.md b/3 Resources/Linux/APT.md new file mode 100644 index 0000000..9231d40 --- /dev/null +++ b/3 Resources/Linux/APT.md @@ -0,0 +1,5 @@ +#linux #packages #how-to + +--- +reinstall packages: +`apt reinstall <pkg>`
\ No newline at end of file diff --git a/3 Resources/Linux/Definitions.md b/3 Resources/Linux/Definitions.md new file mode 100644 index 0000000..c0ca4dd --- /dev/null +++ b/3 Resources/Linux/Definitions.md @@ -0,0 +1,6 @@ +#linux #definitions + +--- +NBP = Network Bootstrap Program +PXE = Preboot Execution Environment +NIC = Network Interface Card
\ No newline at end of file diff --git a/3 Resources/Linux/Device drivers.md b/3 Resources/Linux/Device drivers.md new file mode 100644 index 0000000..95f1a75 --- /dev/null +++ b/3 Resources/Linux/Device drivers.md @@ -0,0 +1,22 @@ +#linux #devices + +--- +major, minor numbers +major = driver (used by kernel when opening device to dispatch to correct driver) +minor = used by driver to differentiate device(s) + +after disk the major, minor numbers are shown: +``` +[jasras@n04.compute.vps2-lej1 ~]$ ls -l /dev/dm-* +brw-rw---- 1 root disk 253, 0 Oct 25 10:10 /dev/dm-0 +brw-rw---- 1 root disk 253, 1 Oct 25 10:11 /dev/dm-1 +brw-rw---- 1 root root 253, 11 Oct 28 19:58 /dev/dm-11 +brw-rw---- 1 root root 253, 12 Oct 28 19:58 /dev/dm-12 +``` + +available devices: `cat /proc/devices` + +character devices vs block devices; what is the difference? + +--- +[oreilly-device-drivers](https://www.oreilly.com/library/view/linux-device-drivers/0596000081/ch03s02.html)
\ No newline at end of file diff --git a/3 Resources/Linux/Device mapper.md b/3 Resources/Linux/Device mapper.md new file mode 100644 index 0000000..059a0d1 --- /dev/null +++ b/3 Resources/Linux/Device mapper.md @@ -0,0 +1,28 @@ +#linux #device-mapper + +--- +Device mapper is a kernel driver to map physical block devices to virtual ones; this means that for example we can have many physical devices be represented by a single virtual one (linear mapping). + +How does it work? +[[1 projects/Inwerken Mohammed/TODO]] +What is its function in relation to multipath? + +Logical devices using device-mapper can be managed using `man 8 dmsetup` +``` +[jasras@n04.compute.vps2-lej1 ~]$ sudo dmsetup info 3600a098038314d736724566a67346538 +Name: 3600a098038314d736724566a67346538 +State: ACTIVE +Read Ahead: 256 +Tables present: LIVE +Open count: 1 +Event number: 3 +Major, minor: 253, 12 +Number of targets: 1 +UUID: mpath-3600a098038314d736724566a67346538 +``` + +If dmsetup cannot remove a device because a process still has it open, but lsof does not show any processes that open it, use `-f` which replaces the device with a fake that rejects all I/O. + +--- +[device-mapper](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/device_mapper#device_mapper) +[dmsetup](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/dmsetup#dmsetup)
\ No newline at end of file diff --git a/3 Resources/Linux/LSOF.md b/3 Resources/Linux/LSOF.md new file mode 100644 index 0000000..5a3aa95 --- /dev/null +++ b/3 Resources/Linux/LSOF.md @@ -0,0 +1,69 @@ +#linux #how-to + +--- + +``` +lsof -p 1111 # show open files for this PID +lsof /path/to/file # show which process has this open +``` + +A usage in the wild; using lsof to find the qemu process for a specific base image and using that to get instance name and disk path: +``` +lsof -F p {{ item['path'] }} | cut -b 2- | head -1 | xargs ps | grep -oP '(instance\\-[a-z0-9]+)|(\\/var\\/lib\\/nova\\/instances\\/[a-z0-9\\-]+\\/disk)' | uniq +``` + +(man lsof: search "OUTPUT FOR OTHER PROGRAMS") +output for other programs +``` +specify -F +These are the fields that lsof will produce. The single character listed first is the field identifier. + a file access mode + c process command name (all characters from proc or + user structure) + C file structure share count + d file's device character code + D file's major/minor device number (0x<hexadecimal>) + f file descriptor (always selected) + F file structure address (0x<hexadecimal>) + G file flaGs (0x<hexadecimal>; names if +fg follows) + g process group ID + i file's inode number + K tasK ID + k link count + l file's lock status + L process login name + m marker between repeated output + M the task comMand name + n file name, comment, Internet address + N node identifier (ox<hexadecimal> + o file's offset (decimal) + p process ID (always selected) + P protocol name + r raw device number (0x<hexadecimal>) + R parent process ID + s file's size (decimal) + S file's stream identification + t file's type + T TCP/TPI information, identified by prefixes (the + `=' is part of the prefix): + QR=<read queue size> + QS=<send queue size> + SO=<socket options and values> (not all dialects) + SS=<socket states> (not all dialects) + ST=<connection state> + TF=<TCP flags and values> (not all dialects) + WR=<window read size> (not all dialects) + WW=<window write size> (not all dialects) + (TCP/TPI information isn't reported for all supported + UNIX dialects. The -h or -? help output for the + -T option will show what TCP/TPI reporting can be + requested.) + u process user ID + z Solaris 10 and higher zone name + Z SELinux security context (inhibited when SELinux is disabled) + 0 use NUL field terminator character in place of NL + 1-9 dialect-specific field identifiers (The output + of -F? identifies the information to be found + in dialect-specific fields.) + +```
\ No newline at end of file diff --git a/3 Resources/Linux/PXE.md b/3 Resources/Linux/PXE.md new file mode 100644 index 0000000..dcd59e7 --- /dev/null +++ b/3 Resources/Linux/PXE.md @@ -0,0 +1,19 @@ +--- +tags: + - linux +--- +The NBP is a bootloader that is obtained via the network typically via [[TFTP]]. It handles setting up an environment in which an OS can run or install. For example, it displays a boot menu and downloads the kernel images. It sets up hardware, for example the [[NIC]]s. + +PXE boot process: +1. Modified [[DHCP]] request: request to include boot information (PXE boot request). +2. Process DHCP response which includes an IP address of [[TFTP]] server and filename of [[NBP]]. +3. Download NBP over TFTP. +4. NBP executes + 1. Loads additional stuff over network, like kernel images. + 2. Handles the boot menu +5. Kernel takes over boot process and potentially downloads additional files required to complete booting. + +Popular NBP's: +- PXELINUX +- iPXE +- GRUB2 diff --git a/3 Resources/Linux/Users.md b/3 Resources/Linux/Users.md new file mode 100644 index 0000000..885a7cc --- /dev/null +++ b/3 Resources/Linux/Users.md @@ -0,0 +1,22 @@ +#linux #user-management + +Change uid/gid of user +`usermod -u newnumber user` +`groupmod -g newnumber user` + +File permissions in homedir will be automatically updated; file perms outside home dir will not be automatically updated. + +Finding files of a specific user, and printing their uid/gid; +`sudo find / -user 4109 -printf '%p %u(%U) %g(%G)\n'` + +To change only the group: `chgrp`. + +Or using find to chmod/chgrp: +`sudo find / -user 4109 -group 4109 -exec chmod 998:998 {} \;` +`sudo find / -group 4109 -exec chgrp 998 {} \;` + +Dirty way to find "system users" (uid < 999) - note that this is not fool-proof, it also lists groups +`getent passwd | grep -oP '\b[0-9]{3}\b' | uniq | sort` + +--- +https://www.cyberciti.biz/faq/linux-change-user-group-uid-gid-for-all-owned-files/ diff --git a/3 Resources/Linux/Watch.md b/3 Resources/Linux/Watch.md new file mode 100644 index 0000000..0c167b7 --- /dev/null +++ b/3 Resources/Linux/Watch.md @@ -0,0 +1,4 @@ +#linux #how-to + +--- +`watch (1)` periodically executes the executable on argv. It can be used to reload the output of a command, like `sudo watch ovs-dpctl dump-flows` . diff --git a/3 Resources/Linux/filesystems/Tmpfs.md b/3 Resources/Linux/filesystems/Tmpfs.md new file mode 100644 index 0000000..b8fe839 --- /dev/null +++ b/3 Resources/Linux/filesystems/Tmpfs.md @@ -0,0 +1,16 @@ +#linux #filesystem + +--- +Is a [[virtual filesystem]] that is stored in memory; it uses both RAM and swap space. +> Kernel option: CONFIG_TMPFS + +`mount -t tmpfs source target` + +A tmpfs can only grow to 50% of RAM avail. unless overridden with size=nbytes mount option. +Only consumes RAM for actual usage. +Data is ephemeral/volatile. + +Mount stacking: mount over existing /tmp, to improve speed of apps using alot of tmp files, then unmount to delete data. + +Kernel uses tmpfs for [[system v shared memory]] and [[shared anonymous memory mappings]]. +`/dev/shm` or `/run/shm`: [[glibc]] of [[POSIX]] shared memory and [[POSIX]] semaphores.
\ No newline at end of file diff --git a/3 Resources/MermaidJS.md b/3 Resources/MermaidJS.md new file mode 100644 index 0000000..2e4b71e --- /dev/null +++ b/3 Resources/MermaidJS.md @@ -0,0 +1,24 @@ +#resource + +--- +**ZenUML** +Optional **Title** +**Participants** can be declared when used or at the start. +**Annotators** give **participants** a special icon, defined at the doc site. +**Aliases** give a short **participant** name a more descriptive name when rendered, e.g: A as Alice <- Alice will be rendered, but the code can use A. +**Messages** between **participants** can be **sync, async, creation or reply**. +**Sync** use A.\<MessageName\> have a block {} for nested messages +**Async** use an arrow A->B: How are you? +**Creation** new keyword new A(optional params) +**Reply** three ways to define: +* Assign var from **Sync** message, e.g: OptionalType a = A.SyncMessage() +* Return A.SyncMessage { return blaat } +* @return or @reply on an **async** message +**Nesting** can be done on both creation and sync messages using blocks {}. +**Comments** can be added using `// comment` and support markdown. +**Loops** can be defined using keywords: **while, for, foreach and loop**. +**Alternative** paths can be sequenced using **if, else** statements. if(blaat) { A.syncMessage(B) } +**Opt** fragments rendered via `opt { ... }`. This can be useful for optional responses or paths. +**Parallel** paths can be defined using `par { ... }`. +**Try/catch/finally** statements are supported as well. +**@Starter(participant)** to make the line start from a **participant**
\ No newline at end of file diff --git a/3 Resources/MySQL.md b/3 Resources/MySQL.md new file mode 100644 index 0000000..dc44345 --- /dev/null +++ b/3 Resources/MySQL.md @@ -0,0 +1 @@ +Foreign keys live in `information_schema.referential_constraints`.
\ No newline at end of file diff --git a/3 Resources/Networking/DHCP.md b/3 Resources/Networking/DHCP.md new file mode 100644 index 0000000..5297546 --- /dev/null +++ b/3 Resources/Networking/DHCP.md @@ -0,0 +1,6 @@ +--- +tags: + - networking +--- +Dynamic Host Configuration Protocol +Allows hosts dynamically receive an IP address.
\ No newline at end of file diff --git a/3 Resources/Networking/IP masquerade.md b/3 Resources/Networking/IP masquerade.md new file mode 100644 index 0000000..cb9cdc3 --- /dev/null +++ b/3 Resources/Networking/IP masquerade.md @@ -0,0 +1,18 @@ +--- +tags: + - networking +--- +A function in the kernel that allows guests with internal/private IPs to access the internet by using the hosts' public IP similar to 1 to many NAT. + +Differences with Proxy, IP Masq, NAT: + +**Proxy** +Requires special configuration on internal client side. Can be used for caching. + +**IP Masq** +A form of NAT used primarily in Linux devices. Translates IP address and uses the connection tracking table and ports to map responses back to the internal connection. + +**NAT** +Has different types with different use-cases. +Static NAT: 1-1 mapping of pub/private IP. Dynamic NAT: pool of pub ips to dynamically map private IPs to based on availability. +PAT (Port): similar to IP Masq; 1-many using ports.
\ No newline at end of file diff --git a/3 Resources/Networking/Switch.md b/3 Resources/Networking/Switch.md new file mode 100644 index 0000000..66f4652 --- /dev/null +++ b/3 Resources/Networking/Switch.md @@ -0,0 +1,10 @@ +--- +tags: + - linux + - networking +--- +A switch keeps a MAC-Address-Table mapping MAC addresses to connected ports. Connected devices that want to communicate learn each others' MAC address via an ARP request. They can then specify the destination MAC address and the switch will do the forwarding to the correct port. + +Broadcast domain: broadcast traffic will be forwarded to all ports except the port the request arrived on. Broadcast traffic will stay within the broadcast domain as routers that receive a broadcast do not forward it to another [[subnet]]. + +> Large layer 2 broadcast domains can cause problems for example a [[broadcast storm]] which can take down the network diff --git a/3 Resources/Nix/Apply custom patches.md b/3 Resources/Nix/Apply custom patches.md new file mode 100644 index 0000000..370c53a --- /dev/null +++ b/3 Resources/Nix/Apply custom patches.md @@ -0,0 +1,17 @@ +#nix #packages #overlay + +--- +We can apply patches to existing packages using [[Overlays]]: +```nix +final: prev { + nova = prev.nova.overrideAttrs (old: { + patches = (old.patches or []) ++ [ + prev.fetchpatch { + url = "https://github.com/owner/repo/commit/hash.patch"; + hash = "somehash"; + }) + ./relative.patch + ] + }) +} +``` diff --git a/3 Resources/Nix/Build images with Nix.md b/3 Resources/Nix/Build images with Nix.md new file mode 100644 index 0000000..3a02a05 --- /dev/null +++ b/3 Resources/Nix/Build images with Nix.md @@ -0,0 +1,28 @@ +--- +tags: + - nix + - image +--- +`nix-build '<nixpkgs/nixos/release.nix>' -A iso_minimal.x86_64-linux --arg configuration ./nginx-test.nix -o ./result` + +where nginx-test.nix is: +``` +{ pkgs, ... }: +{ + security.acme.acceptTerms = true; + security.acme.email = "jaspert.ras@gmail.com"; + services.nginx = { + enable = true; + recommendedGzipSettings = true; + recommendedOptimisation = true; + recommendedProxySettings = true; + recommendedTlsSettings = true; + virtualHosts."jras.nl" = { + enableACME = true; + forceSSL = true; + locations."/".root = "${pkgs.nginx}/html"; + }; + }; +} +``` + diff --git a/3 Resources/Nix/Flake.md b/3 Resources/Nix/Flake.md new file mode 100644 index 0000000..754556f --- /dev/null +++ b/3 Resources/Nix/Flake.md @@ -0,0 +1,22 @@ +#nix #flake + +--- +Nix flakes are source trees containing a file `flake.nix` at their root. The file `flake.nix` provides a standardized way to provide [[Zettelkast/Index/Nix]] artifacts. It's like a package manager for [[Zettelkast/Index/Nix]]. A flake can be dependent on other Flakes and it's possible to pin dependencies to exact revisions by using a `flake.lock` file. + +Nix flake evaluation is hermetic, meaning that it produces the same result wherever it's built.k + +The feature can be enabled in `~/.config/nix/nix.conf`: + +``` +experimental-features = nix-command flakes +``` + +To initialize in a repo: `nix flake init`. + +In flakes dependencies have to be specified explicitly and MUST be locked to specific versions therefore it's no longer allowed to use the nixpkgs found in `NIX_PATH` by referencing it like `<nixpkgs>`. + +Output of a Flake is an arbitrary [[Zettelkast/Index/Nix]] value such as a package, [[NixOS]] module or library function. +Commands `nix build` and `nix shell` will build the output `packages.<system>.default` unless we specify another output, for example: `nix shell .#checks.aarch64-linux.build`. + +--- +[Flakes Wiki](https://nixos.wiki/wiki/Flakes)
\ No newline at end of file diff --git a/3 Resources/Nix/How Nix works.md b/3 Resources/Nix/How Nix works.md new file mode 100644 index 0000000..07b8623 --- /dev/null +++ b/3 Resources/Nix/How Nix works.md @@ -0,0 +1,22 @@ +--- +tags: + - nix +references: + - https://github.com/NixOS/nixpkgs +--- +The hash in the store path is a hash of the package's dependency graph. Thus it changes if even one dependency changes. This enables many versions of the same package be present in the store, which might be dependencies to other packages.. + +Atomicity -> Packages are never overwritten, only new paths are ever added. + V + Enables rollbacking + +Source deployment model -> Build program + dependencies from source upon installation. +Binary cache -> a web server that provided pre-built binaries. + +Nixpkgs[1] is a set of Nix expressions for building existing UNIX packages. + +NixOS extends Nix by also building configuration, thus enabling the same features for config. + +"NixOS has a _transactional_ approach to configuration management: configuration changes such as upgrades are _atomic_. This means that if the upgrade to a new configuration is interrupted — say, the power fails half-way through — the system will still be in a consistent state: it will either boot in the old or the new configuration. In most other systems, you’ll end up in an inconsistent state, and your machine may not even boot anymore." + +Presumably this means that in some way they make it so the system config is only changed by updating a single point.
\ No newline at end of file diff --git a/3 Resources/Nix/Import.md b/3 Resources/Nix/Import.md new file mode 100644 index 0000000..d201c74 --- /dev/null +++ b/3 Resources/Nix/Import.md @@ -0,0 +1,5 @@ +#nix #keyword + +--- +The import keyword brings a Nix expression from another source into scope such that we can reference it. For example, we can `import <nixpkgs>` and it would bring the entire attribute set that is Nixpkgs into scope and allows us to reference any of its attributes. + diff --git a/3 Resources/Nix/Nix build vm.md b/3 Resources/Nix/Nix build vm.md new file mode 100644 index 0000000..24849a2 --- /dev/null +++ b/3 Resources/Nix/Nix build vm.md @@ -0,0 +1,32 @@ +--- +tags: + - nix + - qemu +--- +`nixos-buildvm` dumps a shell script that: + +Creates an empty filesystem image (qcow2) using qemu-img + +A qemu KVM VM is started +``` +exec /nix/store/5v70rrpzv3jwcg7ixa5k9zk0j0lai3nd-qemu-host-cpu-only-9.1.2/bin/qemu-kvm -cpu max \ + -name tarrel \ + -m 1024 \ + -smp 1 \ + -device virtio-rng-pci \ + -net nic,netdev=user.0,model=virtio -netdev user,id=user.0,"$QEMU_NET_OPTS" \ + -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store \ + -virtfs local,path="${SHARED_DIR:-$TMPDIR/xchg}",security_model=none,mount_tag=shared \ + -virtfs local,path="$TMPDIR"/xchg,security_model=none,mount_tag=xchg \ + -drive cache=writeback,file="$NIX_DISK_IMAGE",id=drive1,if=none,index=1,werror=report -device virtio-blk-pci,bootindex=1,drive=drive1,serial=root \ + -device virtio-keyboard \ + -usb \ + -device usb-tablet,bus=usb-bus.0 \ + -kernel ${NIXPKGS_QEMU_KERNEL_tarrel:-/nix/store/47zad70cn0qi0pkvv21b43qwiis50lis-nixos-system-tarrel-24.11pre-git/kernel} \ + -initrd /nix/store/aqbxrnk7jg7piy7g85npm9xysmrvlihw-initrd-linux-6.6.71/initrd \ + -append "$(cat /nix/store/47zad70cn0qi0pkvv21b43qwiis50lis-nixos-system-tarrel-24.11pre-git/kernel-params) init=/nix/store/47zad70cn0qi0pkvv21b43qwiis50lis-nixos-system-tarrel-24.11pre-git/init regInfo=/nix/store/fii757n9q5f603hmqfdni49lskni93cb-closure-info/registration console=ttyS0,115200n8 console=tty0 $QEMU_KERNEL_PARAMS" \ + $QEMU_OPTS \ + "$@" +``` + +It shared 3 dirs from the host with the guest most notably the nix store. The disk image is used as a [[Wri]]
\ No newline at end of file diff --git a/3 Resources/Nix/Overlays.md b/3 Resources/Nix/Overlays.md new file mode 100644 index 0000000..8ee33f3 --- /dev/null +++ b/3 Resources/Nix/Overlays.md @@ -0,0 +1,11 @@ +#nix #overlay + +--- +Functions that accept two args (conventionally: final, prev) and return a set of [[Package]]s. + +The `prev` arguments holds the set of packages of the "parent" overlay while the `final` argument holds the end result of **all** overlays applied. This means that overlays depend on each other. It is unclear how we can tell on which overlay an overlay depends. + +We can use it to override existing packages or add new packages. + +--- +https://nixos.wiki/wiki/Overlays diff --git a/3 Resources/Nix/Package.md b/3 Resources/Nix/Package.md new file mode 100644 index 0000000..32c6bd4 --- /dev/null +++ b/3 Resources/Nix/Package.md @@ -0,0 +1,6 @@ +#nix #packages + +--- +Packages != NixOS Modules + +Packages come from Nixpkgs.
\ No newline at end of file diff --git a/3 Resources/Nix/REPL.md b/3 Resources/Nix/REPL.md new file mode 100644 index 0000000..210b980 --- /dev/null +++ b/3 Resources/Nix/REPL.md @@ -0,0 +1,5 @@ +#nix #repl + +--- +`nix repl` to interactively evaluate Nix expressions. `:p` if output is not full. + `nix-instantiate --eval <file>.nix` to evaluate a Nix expression from a file. `--strict`.
\ No newline at end of file diff --git a/3 Resources/Nix/Shell.nix.md b/3 Resources/Nix/Shell.nix.md new file mode 100644 index 0000000..13715c2 --- /dev/null +++ b/3 Resources/Nix/Shell.nix.md @@ -0,0 +1,42 @@ +#nix #shell + +--- +Can be used to set up per dir environments, e.g using direnv to automatically activate them. +## Python +https://nixos.org/manual/nixpkgs/stable/#python + +```nix +{ pkgs ? import <nixpkgs> {}}: + +pkgs.mkShell { + packages = [ pkgs.virtualenv ]; +} +``` + +```nix +with import <nixpkgs> {}; +let + my_toolz = python311.pkgs.buildPythonPackage rec { + pname = "toolz"; + version = "0.10.0"; + pyproject = true; + src = fetchPypi { + inherit pname version; + hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; + }; + nativeBuildInputs = [ + python311.pkgs.setuptools + python311.pkgs.wheel + ]; # has no tests + doCheck = false; + meta = { + homepage = "https://github.com/pytoolz/toolz/"; + description = "List processing tools and functional utilities"; + # [...] + }; + }; +in python311.withPackages (ps: with ps; [ numpy my_toolz ]) ).env +``` + +The [[Import]] is required here because imports a nix expression from another source, in this case nixpkgs. +It is not required at line two, because python310Packages itself is already in the local scope.
\ No newline at end of file diff --git a/3 Resources/Obsidian.md b/3 Resources/Obsidian.md new file mode 100644 index 0000000..2c256d2 --- /dev/null +++ b/3 Resources/Obsidian.md @@ -0,0 +1,6 @@ +#resource #obsidian + +Command-palette: CTRL+P +# Templates +Templates can be configured in Settings > Core Plugins > Templates. It requires to have a directory dedicated to templates. We can then insert templates into notes using the command: Insert highlight. +We can also configure a templare for our daily notes, via Settings > Core Plugins > Daily note.
\ No newline at end of file diff --git a/3 Resources/Openstack/Creating ports.md b/3 Resources/Openstack/Creating ports.md new file mode 100644 index 0000000..90223bf --- /dev/null +++ b/3 Resources/Openstack/Creating ports.md @@ -0,0 +1,4 @@ +#openstack #port + +--- +Creating a port with a fixed IP requires admin privileges. It is not sufficient to have an RBAC policy that shares the network with a tenant.
\ No newline at end of file diff --git a/3 Resources/Openstack/Libvirt pmsuspended.md b/3 Resources/Openstack/Libvirt pmsuspended.md new file mode 100644 index 0000000..4749c76 --- /dev/null +++ b/3 Resources/Openstack/Libvirt pmsuspended.md @@ -0,0 +1,6 @@ +#openstack #libvirt + +--- +Encountered a guest running some desktop image that sleeps and puts libvirt domain in state pmsuspend. + +Openstack does not sync power states in this case so the nova instance is still ACTIVE.
\ No newline at end of file diff --git a/3 Resources/Openstack/Nova live migration volume.md b/3 Resources/Openstack/Nova live migration volume.md new file mode 100644 index 0000000..8b37f67 --- /dev/null +++ b/3 Resources/Openstack/Nova live migration volume.md @@ -0,0 +1,18 @@ +#openstack #nova #live-migration #volume + + +--- +Table cinder.volume_attachment, contains which volume_driver. target_lun `(<n>)` here maps to `dm-<n>`. +Luns are not unique across pod, each node has a target_lun 2 and thus dm-2 connected. + +os-brick is responsible for connecting volumes; +if connection_info it receives contains target_iqns, target_luns etc it will not do a scan and just returns those. +`@see os_brick/initiator/connectors/iscsi.py` + +`nova/virt/libvirt/driver.py -> def _connect_volume` does attaching of volumes using os-brick. Driver exposes some methods that do this and are called elsewhere: `swap_volume`, `attach_volume`, `pre_live_migration`. + +`pre_live_migration` is called by `nova/compute/manager.py` + +So in `nova/compute/manager.py` there is a function that does the rollback, and it rollbacks bdm's and deletes volume attachments before it calls `rollback_live_migration_at_destination` which in turn makes an attempt at deleting the actual volume attachment to the node. But at that point all objects have been rollbacked already so it has invalid information. + +If the code in new versions of openstack isn't any different i'll just make a bug report and see what they come up with. diff --git a/3 Resources/Puppet/Classes.md b/3 Resources/Puppet/Classes.md new file mode 100644 index 0000000..701d9b0 --- /dev/null +++ b/3 Resources/Puppet/Classes.md @@ -0,0 +1,14 @@ +--- +tags: + - puppet +references: + - https://www.puppet.com/docs/puppet/7/lang_classes#lang_classes +--- +Contains resource declarations +Written in manifest files, 1 class per file +Declare class to manage -> [[Declaring classes]] +Classname -> unique +Reusable, 1 per node + +Can have parameters, prefer supplying defaults, not having default == required. +`$title` and `$name` are always there and can't be defined by user.
\ No newline at end of file diff --git a/3 Resources/Puppet/Declaring classes.md b/3 Resources/Puppet/Declaring classes.md new file mode 100644 index 0000000..793d4b3 --- /dev/null +++ b/3 Resources/Puppet/Declaring classes.md @@ -0,0 +1,27 @@ +--- +tags: + - puppet +references: + - https://www.puppet.com/docs/puppet/7/lang_classes#lang_class_declare +--- +Prefer include over resource-like; more flexible and idempotent. Resource-like to pass args without needing to use hieradata. + +> Mixing declaration types for the same class can lead to compilation errors. + +# Include-like <- preferred +Relies on external data, e.g hieradata, and defaults. +Idempotent: it is only added to the catalog once. + +### `include` +Accepts: single class, class reference (`Class[..]`), comma-seperated list of those or an array of them. + +## `require` +Same as above - but the class becomes a dependency of the container. #clarify dependency. + +## `contain` +Adheres to same rules as above. Relationships of the containing class extend to the contained class. +See [[Containment]]. + +# Resource-like +Can be declared only once. +Must be unique to avoid conflicting parameter values.
\ No newline at end of file diff --git a/3 Resources/Puppet/ERB template.md b/3 Resources/Puppet/ERB template.md new file mode 100644 index 0000000..08b47f4 --- /dev/null +++ b/3 Resources/Puppet/ERB template.md @@ -0,0 +1,11 @@ +--- +tags: + - erb + - ruby + - template + - "#puppet" +--- +`<%-` trims indentation +`-%>` trims line-breaks + +In case of if-else
\ No newline at end of file diff --git a/3 Resources/Puppet/Replace a line in a file.md b/3 Resources/Puppet/Replace a line in a file.md new file mode 100644 index 0000000..5a6f23b --- /dev/null +++ b/3 Resources/Puppet/Replace a line in a file.md @@ -0,0 +1,32 @@ +--- +tags: + - puppet +--- +``` + file_line { + '/etc/sysconfig/libvirt-guests onboot': + path => '/etc/default/libvirt-guests', + line => 'ON_BOOT=ignore', + match => 'ON_BOOT='; + '/etc/libvirt/qemu.conf vnctls': + path => '/etc/libvirt/qemu.conf', + line => 'vnc_tls = 0', + match => '^#?vnc_tls = ', + notify => Service['libvirt']; + '/etc/libvirt/qemu.conf vnctls_verify': + path => '/etc/libvirt/qemu.conf', + line => 'vnc_tls_x509_verify = 0', + match => 'vnc_tls_x509_verify =', + notify => Service['libvirt']; + '/etc/libvirt/qemu.conf tls': + path => '/etc/libvirt/qemu.conf', + match => '^default_tls_x509_cert_dir = "/etc/pki/qemu"$', + line => '#default_tls_x509_cert_dir = "/etc/pki/qemu"', + notify => Service['libvirt']; + '/etc/libvirt/qemu.conf tls_verify': + path => '/etc/libvirt/qemu.conf', + match => '^default_tls_x509_verify = 1$', + line => '#default_tls_x509_verify = 1', + notify => Service['libvirt']; + } +``` diff --git a/3 Resources/Puppet/Resource type references.md b/3 Resources/Puppet/Resource type references.md new file mode 100644 index 0000000..b0f2b36 --- /dev/null +++ b/3 Resources/Puppet/Resource type references.md @@ -0,0 +1,6 @@ +--- +tags: + - puppet + - reference +--- +- [User](https://www.puppet.com/docs/puppet/7/types/user.html) diff --git a/3 Resources/Puppet/Sensitive type.md b/3 Resources/Puppet/Sensitive type.md new file mode 100644 index 0000000..eed8e85 --- /dev/null +++ b/3 Resources/Puppet/Sensitive type.md @@ -0,0 +1,17 @@ +--- +tags: + - puppet +references: + - https://www.puppet.com/docs/puppet/7/lang_data_sensitive.html +--- +Cannot be used as a typedef in the class arguments because hieradata doesn't pass it as such but as a regular string. + +The `unwrap` method gives access to the original data. + +It doesn't encrypt anything - its only purpose is the hiding of data from logs and reports. + +To use Sensitive with a template we can wrap the `template` reference in it. Such as this: +``` +'/etc/dnsdist/dnsdist.conf': + content => Sensitive(template('profile/application/dnsdist.conf.erb')); +``` diff --git a/3 Resources/Python/Make dataclass dict-able.md b/3 Resources/Python/Make dataclass dict-able.md new file mode 100644 index 0000000..d8ee02b --- /dev/null +++ b/3 Resources/Python/Make dataclass dict-able.md @@ -0,0 +1,15 @@ +--- +tags: + - python + - "#how-to" +references: + - https://docs.python.org/3/library/functions.html#vars + - https://docs.python.org/3/reference/datamodel.html#object.__iter__ +--- +The `dict` method takes kwargs and creates a dict from that. If we want to pass an object into it the object implement the `__iter__` method. +We can use `vars` to make that easy: +``` +def __iter__(self): + for k, v in vars(self): + yield k, v +```
\ No newline at end of file diff --git a/3 Resources/Python/__getitem__ __setitem__.md b/3 Resources/Python/__getitem__ __setitem__.md new file mode 100644 index 0000000..03c890e --- /dev/null +++ b/3 Resources/Python/__getitem__ __setitem__.md @@ -0,0 +1,5 @@ +--- +tags: + - python +--- +To have a class behave as a dict it's possible to add the two magic methods `__getitem__(self, key)` and `__setitem__(self, key, val)`.
\ No newline at end of file diff --git a/3 Resources/RabbitMQ.md b/3 Resources/RabbitMQ.md new file mode 100644 index 0000000..312bec2 --- /dev/null +++ b/3 Resources/RabbitMQ.md @@ -0,0 +1 @@ +With `rabbitmqctl list_queues` we can add columns to show. So instead of the default layout which shows messages in the Q after the name and is horrible we can specify stuff like: `rabbitmqctl list_queues messages consumers name`. There are more options to be found in `man rabbitmqctl`. diff --git a/3 Resources/Ripgrep.md b/3 Resources/Ripgrep.md new file mode 100644 index 0000000..b8ce387 --- /dev/null +++ b/3 Resources/Ripgrep.md @@ -0,0 +1 @@ +Pass `-L` to `rg` to make it follow symlinks: this is handy for example when searching hieradata, because node definitions can be symlinked.
\ No newline at end of file diff --git a/3 Resources/Statistics/Moving average.md b/3 Resources/Statistics/Moving average.md new file mode 100644 index 0000000..c87f0e4 --- /dev/null +++ b/3 Resources/Statistics/Moving average.md @@ -0,0 +1,20 @@ +#statistics + +--- +Also known as; rolling-average, running-average, moving-mean, running-mean, rolling-mean. + +Has three variations: simple, weighted, cumulative. + +A type of [[convolution]]. + +Reduces noisiness in a time-series graph which makes long-term trends or cycles more easily visible. + +Keeps averaging a subset of given set and move the subset one space to the right. +Example with sample-size of 3: +``` +set: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +i=1: avg([0, 1, 2]) = 1 +i=2: avg([1, 2, 3]) = 2 +i=3: avg([2, 3, 4]) = 3 +... +``` diff --git a/3 Resources/Systemd/Unit types.md b/3 Resources/Systemd/Unit types.md new file mode 100644 index 0000000..27ee387 --- /dev/null +++ b/3 Resources/Systemd/Unit types.md @@ -0,0 +1,14 @@ +--- +tags: + - systemd + - linux +--- +The `Type` directive is specified within the `Service` section. There are 6 different types; +- **Simple**: The default if `Type` nor `Busname` are specified. +- **Forking**: Used when the parent process exits immediately due to it forking. Systemd will know it's still running even though it exited. +- **Oneshot**: When the process is short-lived and doesn't need to keep running. Systemd will wait on the process before starting other units. +- **Dbus**: The process will be registered on the D-Bus bus. +- **Notify**: Systemd will expect a notification from the process to signal it has started up blocking the execution of other units until the signal is received. +- **Idle**: Service will not run ufntil all jobs are dispatched. #clarify + +https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files#unit-specific-section-directives
\ No newline at end of file diff --git a/3 Resources/TailwindCSS/Container.md b/3 Resources/TailwindCSS/Container.md new file mode 100644 index 0000000..4b3e6ca --- /dev/null +++ b/3 Resources/TailwindCSS/Container.md @@ -0,0 +1,2 @@ +The container class basically adds a margin to the left and right sides. If added mx-auto; it divides the margin equally over both sides. +The margin depends on the current breakpoint. The container max-width is the breakpoints' min-width. diff --git a/3 Resources/TailwindCSS/Prevent overflow.md b/3 Resources/TailwindCSS/Prevent overflow.md new file mode 100644 index 0000000..8a4abed --- /dev/null +++ b/3 Resources/TailwindCSS/Prevent overflow.md @@ -0,0 +1,3 @@ +When creating the wedding invitation I had an issue where the page would allow +scroll horizontally because the flower on the top-right was too big. +Adding the tailwindcss class `overflow-hidden` basically hides all parts that overflow from the container. diff --git a/3 Resources/Taskwarrior.md b/3 Resources/Taskwarrior.md new file mode 100644 index 0000000..34fe640 --- /dev/null +++ b/3 Resources/Taskwarrior.md @@ -0,0 +1,4 @@ +`task add something +label` +`task context none` +`task add highprio thing +label priority:H` +`task context define mycontext +label project:blaat` diff --git a/3 Resources/Technical terms.md b/3 Resources/Technical terms.md new file mode 100644 index 0000000..cade443 --- /dev/null +++ b/3 Resources/Technical terms.md @@ -0,0 +1,10 @@ +--- +tags: + - definitions + - reference +--- + +**Slug** +A user-friendly representation of the name of a page used in the path of an URL. +For example a page titled: My Friends And I, would be referenced via its slug: my-friends-and-i or my-friends-i. +It can be optimized for brevity so its easier to type and remember. diff --git a/3 Resources/Testing/Anatomy of a test.md b/3 Resources/Testing/Anatomy of a test.md new file mode 100644 index 0000000..c7218a1 --- /dev/null +++ b/3 Resources/Testing/Anatomy of a test.md @@ -0,0 +1,15 @@ +--- +tags: + - python + - testing + - pytest +references: + - https://docs.pytest.org/en/stable/explanation/anatomy.html#test-anatomy +--- +Tests look at the result of how the system under test (SUT) responds to a certain input. It shouldn't care too much about how or why something was done, but mainly about what was done. + +A test can be seperated into four stages: +- Arrange: prepares everything needed to run the test. +- Act: the singular action that triggers the behaviour that's being tested. +- Assert: looking at what changed in response to the action. +- Cleanup: make sure that tests do not influence other tests - by resetting to a "clean" state.
\ No newline at end of file diff --git a/3 Resources/ansible/ad-hoc-commands.md b/3 Resources/ansible/ad-hoc-commands.md new file mode 100644 index 0000000..eda1265 --- /dev/null +++ b/3 Resources/ansible/ad-hoc-commands.md @@ -0,0 +1,25 @@ +Using ansible we can perform ad-hoc commands, useful for a one-off thing that won't require writing a full playbook. + +Some examples include: +update apt cache: +``` +ansible <pattern> -m ansible.builtin.apt -a "update_cache=true cache_valid_time=3600" +``` + +update packages: +``` +ansible <pattern> -m ansible.builtin.apt -a "name=* state=latest" +``` + +run puppet: +``` +ansible <pattern> -a "/opt/puppetlabs/bin/puppet agent --test" +``` + +reboot: +``` +ansible <pattern> -m ansible.builtin.reboot -f 1 +``` + +[[ansible]] +#ansible
\ No newline at end of file diff --git a/3 Resources/ansible/ansible.md b/3 Resources/ansible/ansible.md new file mode 100644 index 0000000..5886288 --- /dev/null +++ b/3 Resources/ansible/ansible.md @@ -0,0 +1 @@ +At its heart it's just an abstraction over running commands remotely over SSH. It enables some powerful automation like setting up a server following a predetermined script.
\ No newline at end of file diff --git a/3 Resources/ansible/build-array-loop.md b/3 Resources/ansible/build-array-loop.md new file mode 100644 index 0000000..15f441f --- /dev/null +++ b/3 Resources/ansible/build-array-loop.md @@ -0,0 +1,6 @@ +How to construct an array variable containing results of an iterative ansible task? +Use register. The referenced variable will contain a property results which is a list containing the combined outputs of the loop. + +https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#registering-variables-with-a-loop + +[[ansible]]
\ No newline at end of file diff --git a/3 Resources/ansible/build-list-silences.md b/3 Resources/ansible/build-list-silences.md new file mode 100644 index 0000000..dc8ef61 --- /dev/null +++ b/3 Resources/ansible/build-list-silences.md @@ -0,0 +1 @@ +Explain what I did today at work to build a list of silences and then have one task to unsilence all of them.
\ No newline at end of file diff --git a/3 Resources/ansible/debug.md b/3 Resources/ansible/debug.md new file mode 100644 index 0000000..552af1f --- /dev/null +++ b/3 Resources/ansible/debug.md @@ -0,0 +1,29 @@ +``` +- name: Print the gateway for each host when defined + ansible.builtin.debug: + msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }} + when: ansible_default_ipv4.gateway is defined + +- name: Get uptime information + ansible.builtin.shell: /usr/bin/uptime + register: result + +- name: Print return information from the previous task + ansible.builtin.debug: + var: result + verbosity: 2 + +- name: Display all variables/facts known for a host + ansible.builtin.debug: + var: hostvars[inventory_hostname] + verbosity: 4 + +- name: Prints two lines of messages, but only if there is an environment value set + ansible.builtin.debug: + msg: + - "Provisioning based on YOUR_KEY which is: {{ lookup('ansible.builtin.env', 'YOUR_KEY') }}" + - "These servers were built using the password of '{{ password_used }}'. Please retain this for later use." +``` + +--- +https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html
\ No newline at end of file diff --git a/3 Resources/ansible/default-filter.md b/3 Resources/ansible/default-filter.md new file mode 100644 index 0000000..2255e71 --- /dev/null +++ b/3 Resources/ansible/default-filter.md @@ -0,0 +1,7 @@ +Using the default filter, if we reference an undefined variable we can set a default: `{{ var | default([]) }}`. + +defaults: +- int +- str +- list ([]) +- dict ({})
\ No newline at end of file diff --git a/3 Resources/ansible/delegate-to.md b/3 Resources/ansible/delegate-to.md new file mode 100644 index 0000000..270ccb1 --- /dev/null +++ b/3 Resources/ansible/delegate-to.md @@ -0,0 +1,3 @@ +Through the use of delegate to, we can run a task for certain nodes and delegate work on behalf of those nodes to other hosts. + +A great example of usage is this: diff --git a/3 Resources/ansible/dicts.md b/3 Resources/ansible/dicts.md new file mode 100644 index 0000000..eac3d1b --- /dev/null +++ b/3 Resources/ansible/dicts.md @@ -0,0 +1 @@ +Merged using combine: `{{ dict1 | ansible.builtin.combine(dict2) }}`
\ No newline at end of file diff --git a/3 Resources/ansible/extra-vars.md b/3 Resources/ansible/extra-vars.md new file mode 100644 index 0000000..07b0764 --- /dev/null +++ b/3 Resources/ansible/extra-vars.md @@ -0,0 +1,8 @@ +We can pass variables to the ansible upon invoking it using `--extra-vars` or `-e`. + +``` +--extra-vars "blaat=piet henk=joop" +--extra-vars '{"blaat":"piet","henk":"joop"}' +--extra-vars "@file.json" +--extra-vars "@file.yml" +``` diff --git a/3 Resources/ansible/find.md b/3 Resources/ansible/find.md new file mode 100644 index 0000000..1f4de51 --- /dev/null +++ b/3 Resources/ansible/find.md @@ -0,0 +1,9 @@ +``` +- name: Find file with size >= 50G + ansible.builtin.find: + paths: + - /var/lib/nova/instances/_base + size: 50g +``` +--- +https://docs.ansible.com/ansible/latest/collections/ansible/builtin/find_module.html
\ No newline at end of file diff --git a/3 Resources/ansible/loop-output.md b/3 Resources/ansible/loop-output.md new file mode 100644 index 0000000..30a0848 --- /dev/null +++ b/3 Resources/ansible/loop-output.md @@ -0,0 +1 @@ +Using the label field we can select what to print, instead of the whole item.
\ No newline at end of file diff --git a/3 Resources/ansible/loop-register.md b/3 Resources/ansible/loop-register.md new file mode 100644 index 0000000..bab52a5 --- /dev/null +++ b/3 Resources/ansible/loop-register.md @@ -0,0 +1,41 @@ +When using a loop the registered variable will contain the results of all the responses: +```JSON +{ + "changed": true, + "msg": "All items completed", + "results": [ + { + "changed": true, + "cmd": "echo \"one\" ", + "delta": "0:00:00.003110", + "end": "2013-12-19 12:00:05.187153", + "invocation": { + "module_args": "echo \"one\"", + "module_name": "shell" + }, + "item": "one", + "rc": 0, + "start": "2013-12-19 12:00:05.184043", + "stderr": "", + "stdout": "one" + }, + { + "changed": true, + "cmd": "echo \"two\" ", + "delta": "0:00:00.002920", + "end": "2013-12-19 12:00:05.245502", + "invocation": { + "module_args": "echo \"two\"", + "module_name": "shell" + }, + "item": "two", + "rc": 0, + "start": "2013-12-19 12:00:05.242582", + "stderr": "", + "stdout": "two" + } + ] +} +``` + +Thus we can loop over each results `{{ registered_var.results }}`.
\ No newline at end of file diff --git a/3 Resources/ansible/loop-results-prior-loop.md b/3 Resources/ansible/loop-results-prior-loop.md new file mode 100644 index 0000000..cbd50a2 --- /dev/null +++ b/3 Resources/ansible/loop-results-prior-loop.md @@ -0,0 +1,30 @@ +```YAML +- name: First loop + loop: {{ blaat }} + register: loooped + ... + +- name: Second loop + loop: {{ loooped.results }} + when: item.skipped is not defined +``` + +this loops over results of prior loop only but does not process any skipped results. + +In case the results array contains another array that we want to loop over, for example when we did a shell command in a loop we can use extract: +``` +- name: Print magic + ansible.builtin.debug: + msg: "{{ ['stdout_lines'] | map('extract', item) }}" + loop: "{{ magic.results }}" +``` + +A cool example of this in practice: +``` +- name: Print blockpull command + ansible.builtin.debug: + msg: "virsh blockpull {{ ['stdout_lines'] | map('extract', item) | list | flatten | join(' ') }}" + loop: "{{ domain_and_disk_paths.results }}" + loop_control: + label: "{{ inventory_hostname }}" +```
\ No newline at end of file diff --git a/3 Resources/ansible/nested-loops.md b/3 Resources/ansible/nested-loops.md new file mode 100644 index 0000000..fded56a --- /dev/null +++ b/3 Resources/ansible/nested-loops.md @@ -0,0 +1,3 @@ +Nested loops can be done not by nesting loops over two separate lists, but by looping over the [[Cartesian product]] of the two using the `product` filter. + +`{{ list1 | product(list) | list }}`
\ No newline at end of file diff --git a/3 Resources/ansible/set-facts.md b/3 Resources/ansible/set-facts.md new file mode 100644 index 0000000..e94eeb6 --- /dev/null +++ b/3 Resources/ansible/set-facts.md @@ -0,0 +1 @@ +These can be used to set and update variables specific to nodes, at runtime.
\ No newline at end of file diff --git a/3 Resources/libvirt/Mediated devices.md b/3 Resources/libvirt/Mediated devices.md new file mode 100644 index 0000000..fe9e551 --- /dev/null +++ b/3 Resources/libvirt/Mediated devices.md @@ -0,0 +1,11 @@ +#libvirt #linux #virtualisation + +--- +https://libvirt.org/drvnodedev.html#mediated-devices-mdevs + +They are virtual devices that share a single physical device. + +Similar to [[SR-IOV]] but sr-iov required registering and unregistering devices with the host PCIe bus via a host driver. +Mediated devices don't have to do this. + +So why would we still choose sriov?
\ No newline at end of file diff --git a/3 Resources/libvirt/SR-IOV.md b/3 Resources/libvirt/SR-IOV.md new file mode 100644 index 0000000..0881ec0 --- /dev/null +++ b/3 Resources/libvirt/SR-IOV.md @@ -0,0 +1,9 @@ +#linux #libvirt #virtualisation + +--- +Single root input/output virtualization: enables sharing of single PCI-e devices with multiple guests. + +Physical device = PF (Physical Function) +Virtual device = VF (Virtual Function) + +A PF is divided (by manufacturer) into *n* VFs. Thus a PF can be shared at most with *n* guests.
\ No newline at end of file diff --git a/3 Resources/math/Cartesian product.md b/3 Resources/math/Cartesian product.md new file mode 100644 index 0000000..161b405 --- /dev/null +++ b/3 Resources/math/Cartesian product.md @@ -0,0 +1,4 @@ +#math #definitions + +--- +The Cartesian product in [[set theory]] denoted as A x B where A and B are both sets and it would result in pairs of (a, b) for each a and b in A and B respectively.
\ No newline at end of file |