Compare commits
6 Commits
c407e8be9e
...
d1a1146260
Author | SHA1 | Date | |
---|---|---|---|
d1a1146260
|
|||
3dface826f
|
|||
a55712032b
|
|||
33a959fcea
|
|||
4ed4c87acf
|
|||
68f9eb2a7d
|
22
Makefile
22
Makefile
@@ -6,7 +6,7 @@ FZF != command -v sk || command -v fzy || command -v fzf || \
|
|||||||
|
|
||||||
spill_contents = sed -e '1,/---/d'
|
spill_contents = sed -e '1,/---/d'
|
||||||
|
|
||||||
help: ## Print the help message
|
help: .git/info/exclude ## Print the help message
|
||||||
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z._-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) | \
|
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z._-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) | \
|
||||||
sort | \
|
sort | \
|
||||||
column -s ':' -t
|
column -s ':' -t
|
||||||
@@ -19,6 +19,8 @@ categories = $(patsubst %/, %, $(dirs))
|
|||||||
databases = $(patsubst %, .dbs/%.rec, $(categories))
|
databases = $(patsubst %, .dbs/%.rec, $(categories))
|
||||||
|
|
||||||
default += $(databases)
|
default += $(databases)
|
||||||
|
default += db.rec
|
||||||
|
default += .dbs/map.fmt
|
||||||
|
|
||||||
$(foreach dir, $(categories), \
|
$(foreach dir, $(categories), \
|
||||||
$(eval .dbs/$(dir).rec: $(wildcard $(dir)/*)) \
|
$(eval .dbs/$(dir).rec: $(wildcard $(dir)/*)) \
|
||||||
@@ -26,6 +28,7 @@ $(foreach dir, $(categories), \
|
|||||||
|
|
||||||
.dbs/:
|
.dbs/:
|
||||||
mkdir $@
|
mkdir $@
|
||||||
|
|
||||||
$(databases): .dbs/%.rec: %/ | .dbs/
|
$(databases): .dbs/%.rec: %/ | .dbs/
|
||||||
$(info making $(@F))
|
$(info making $(@F))
|
||||||
for entry in $(shell find $< -type f -name "*.md") ; do \
|
for entry in $(shell find $< -type f -name "*.md") ; do \
|
||||||
@@ -38,6 +41,7 @@ $(databases): .dbs/%.rec: %/ | .dbs/
|
|||||||
|
|
||||||
# This two-variable read can only happen because of the quotes in the titles.
|
# This two-variable read can only happen because of the quotes in the titles.
|
||||||
db.rec: $(databases)
|
db.rec: $(databases)
|
||||||
|
$(warning rebuilding from $? )
|
||||||
printf '%s\n' '%rec: guide' > $@
|
printf '%s\n' '%rec: guide' > $@
|
||||||
printf '%s\n' '%key: title' >> $@
|
printf '%s\n' '%key: title' >> $@
|
||||||
printf '%s\n' '%type: requires rec guide' >> $@
|
printf '%s\n' '%type: requires rec guide' >> $@
|
||||||
@@ -55,10 +59,8 @@ db.rec: $(databases)
|
|||||||
recfix --sort $@
|
recfix --sort $@
|
||||||
$(info Created main database: $@)
|
$(info Created main database: $@)
|
||||||
|
|
||||||
default += db.rec
|
|
||||||
|
|
||||||
.git/info/exclude: $(default)
|
.git/info/exclude: $(default)
|
||||||
echo $^ | tr ' ' '\n' > $@
|
@echo $^ | tr ' ' '\n' > $@
|
||||||
|
|
||||||
default += .git/info/exclude
|
default += .git/info/exclude
|
||||||
|
|
||||||
@@ -76,6 +78,18 @@ article: ## Write an article
|
|||||||
printf '%s\n\n' '---' >> $$path/$$filename.md ;\
|
printf '%s\n\n' '---' >> $$path/$$filename.md ;\
|
||||||
$(EDITOR) +5 "$$path/$$filename.md"
|
$(EDITOR) +5 "$$path/$$filename.md"
|
||||||
|
|
||||||
|
.dbs/map.fmt:| .dbs/
|
||||||
|
printf '%s\n' '[ {{requires[0]}} ] --> [ {{title}} ] {border-style: dashed;}' > $@
|
||||||
|
printf '%s\n' '[ {{requires[1]}} ] --> [ {{title}} ] {border-style: dashed;}' >> $@
|
||||||
|
printf '%s\n' '[ {{requires[2]}} ] --> [ {{title}} ] {border-style: dashed;}' >> $@
|
||||||
|
printf '%s\n' '[ {{requires[3]}} ] --> [ {{title}} ] {border-style: dashed;}' >> $@
|
||||||
|
printf '%s\n' '[ {{requires[4]}} ] --> [ {{title}} ] {border-style: dashed;}' >> $@
|
||||||
|
|
||||||
|
.PHONY: map
|
||||||
|
map: db.rec .dbs/map.fmt ## Show knowledge dependency map
|
||||||
|
recsel -t guide $< -e 'requires != ""' -p title,requires | recfmt -f .dbs/map.fmt |\
|
||||||
|
grep -vF '[ ]' | graph-easy --boxart | $${PAGER}
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean: ## Remove all generated files
|
clean: ## Remove all generated files
|
||||||
$(RM) $(default)
|
$(RM) $(default)
|
||||||
|
13
data/json.md
Normal file
13
data/json.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
title: "ijq"
|
||||||
|
tags: [ "data", "json", "TUI" ]
|
||||||
|
---
|
||||||
|
|
||||||
|
Analyse `json` easier with `ijq`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
column -J -ts: -H PW,GID,shell -N User,PW,UID,GID,Description,Home,shell /etc/passwd > host.json
|
||||||
|
ijq !$
|
||||||
|
```
|
||||||
|
|
||||||
|
If you get stuck, try adding `.[]`.
|
114
system/ansible/ansible_with_docker.md
Normal file
114
system/ansible/ansible_with_docker.md
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
---
|
||||||
|
title: "Ansible with Docker"
|
||||||
|
tags: [ "system", "ansible", "docker" ]
|
||||||
|
requires: [ "Docker" ]
|
||||||
|
---
|
||||||
|
|
||||||
|
Set up two containers: `deb` and `arch`, add them to an `ansible` hosts file, then do a 'ping' to see if they respond.
|
||||||
|
|
||||||
|
## Required Packages
|
||||||
|
|
||||||
|
- `ansible`
|
||||||
|
- `jq`
|
||||||
|
- `docker`
|
||||||
|
|
||||||
|
## Debian Container
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker run -di --rm --name deb --hostname deb debian
|
||||||
|
docker exec -it deb sh -c 'apt update && apt -y install openssh-server python3 sudo'
|
||||||
|
```
|
||||||
|
|
||||||
|
Generate the host's ssh keys, then start the ssh daemon:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker exec -it deb sh -c 'ssh-keygen -A'
|
||||||
|
docker exec -d deb /usr/sbin/sshd -D
|
||||||
|
```
|
||||||
|
|
||||||
|
## Arch Linux Container
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker run -di --rm --name arch --hostname arch archlinux
|
||||||
|
docker exec -it arch sh -c 'pacman -Syu --noconfirm python sudo openssh'
|
||||||
|
docker exec -it arch sh -c 'ssh-keygen -A'
|
||||||
|
docker exec -d arch /usr/sbin/sshd -D
|
||||||
|
```
|
||||||
|
|
||||||
|
## `ssh` Keys
|
||||||
|
|
||||||
|
Copy across your public ssh key to the container's `authorized_keys` file:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pubkey=~/.ssh/id_rsa.pub
|
||||||
|
for hostname in arch deb; do
|
||||||
|
docker cp $pubkey $hostname:/root/.ssh/authorized_keys
|
||||||
|
docker exec -it $hostname sh -c "chown -R root:root /root/.ssh/"
|
||||||
|
docker exec -it $hostname sh -c "chmod -R 700 /root/.ssh/"
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
## Hosts File
|
||||||
|
|
||||||
|
Find name of containers' IPv4 addresses.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker network inspect bridge
|
||||||
|
```
|
||||||
|
|
||||||
|
The output is awful.
|
||||||
|
Use `jq` to parse the `json`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker network inspect bridge | jq -r '.[].Containers | .[].IPv4Address'
|
||||||
|
```
|
||||||
|
|
||||||
|
Now put those into a host file:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker_hosts=hosts.txt
|
||||||
|
echo '[containers]' > $docker_hosts
|
||||||
|
|
||||||
|
docker network inspect bridge | \
|
||||||
|
jq -r '.[].Containers | .[] | "root@" + .IPv4Address' | \
|
||||||
|
cut -d/ -f1 >> $docker_hosts
|
||||||
|
```
|
||||||
|
|
||||||
|
You may need to add those host keys to your known hosts file.
|
||||||
|
Either connect interactively, or (for scripts):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
hosts="$(docker network inspect bridge | jq -r '.[].Containers | .[] | .Name + " " + .IPv4Address' | \
|
||||||
|
cut -d/ -f1)"
|
||||||
|
|
||||||
|
echo "$hosts"
|
||||||
|
|
||||||
|
echo "$hosts" | while read hostname ip; do
|
||||||
|
printf "%s" "$ip"
|
||||||
|
key="$(docker exec $hostname cat /etc/ssh/ssh_host_ed25519_key.pub)"
|
||||||
|
echo "$ip $key" >> ~/.ssh/known_hosts
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
Check if they ping:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ansible -i $docker_hosts all -m ping
|
||||||
|
```
|
||||||
|
|
||||||
|
This command produces an irritating warning about the python interpreter (i.e., `python3`).
|
||||||
|
|
||||||
|
Make the warning shut-up:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo '
|
||||||
|
[containers:vars]
|
||||||
|
ansible_python_interpreter=/usr/bin/python3.13' >> $docker_hosts
|
||||||
|
```
|
||||||
|
|
||||||
|
Now the ping is cleaner:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ansible -i $docker_hosts all -m ping
|
||||||
|
```
|
||||||
|
|
@@ -17,10 +17,10 @@ Remove yourself from all groups, and add yourself back to only `wheel`, `audio`,
|
|||||||
sudo usermod --groups wheel,audio,$USER
|
sudo usermod --groups wheel,audio,$USER
|
||||||
```
|
```
|
||||||
|
|
||||||
Add yourself to the `wheel` group:
|
Add yourself to the `docker` group:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
su root -c "usermod --append --groups wheel $USER"
|
su root -c "usermod --append --groups docker $USER"
|
||||||
```
|
```
|
||||||
Add yourself to the `network` group:
|
Add yourself to the `network` group:
|
||||||
|
|
||||||
@@ -28,5 +28,11 @@ Add yourself to the `network` group:
|
|||||||
sudo usermod -aG network $USER
|
sudo usermod -aG network $USER
|
||||||
```
|
```
|
||||||
|
|
||||||
The changes will not take effect until you log in again, so reboot or log into `localhost` with [ssh](../networking/ssh.md).
|
The changes have not taken effect, so log into your own account again with `su`:
|
||||||
|
|
||||||
|
|
||||||
|
```sh
|
||||||
|
groups
|
||||||
|
sudo su $USER
|
||||||
|
groups
|
||||||
|
```
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: "Docker"
|
title: "Docker"
|
||||||
tags: [ "documentation", "virtualization" ]
|
tags: [ "documentation", "virtualization" ]
|
||||||
|
requires: [ "Managing Groups" ]
|
||||||
---
|
---
|
||||||
```sh
|
```sh
|
||||||
sudo pacman -S docker
|
sudo pacman -S docker
|
||||||
|
Reference in New Issue
Block a user