refactor(ansible): разложить репозиторий по схеме Ansible
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a23232ac1c
commit
27f15e7bc7
23 files changed
+277
-242
No files matched your search
@@ -30,10 +30,10 @@ jobs:
|
||||
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
apt-get update
|
||||
apt-get install -y git openssh-client ansible-core
|
||||
apt-get install -y git openssh-client ansible-core python3
|
||||
else
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y git openssh-client ansible-core
|
||||
sudo apt-get install -y git openssh-client ansible-core python3
|
||||
fi
|
||||
|
||||
rm -rf /tmp/homelab-infra
|
||||
@@ -47,24 +47,28 @@ jobs:
|
||||
printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519"
|
||||
chmod 600 "${HOME}/.ssh/id_ed25519"
|
||||
|
||||
inventory=/tmp/homelab-infra/inventory/hosts.ini
|
||||
target=$(awk '{
|
||||
for (i = 1; i <= NF; i++) {
|
||||
if ($i ~ /^ansible_host=/) {
|
||||
split($i, a, "=")
|
||||
print a[2]
|
||||
exit
|
||||
}
|
||||
}
|
||||
}' "${inventory}")
|
||||
if [ -z "${target}" ]; then
|
||||
echo "В inventory/hosts.ini нет ansible_host." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Цель из inventory: ${target}"
|
||||
ssh-keyscan -H "${target}" >> "${HOME}/.ssh/known_hosts"
|
||||
cd /tmp/homelab-infra
|
||||
ansible-inventory -i inventories/prod/hosts.yml --list > /tmp/inventory.json
|
||||
python3 - <<'PY'
|
||||
import json, subprocess
|
||||
data = json.load(open("/tmp/inventory.json"))
|
||||
hosts = data.get("netbird", {}).get("hosts", [])
|
||||
hostvars = data.get("_meta", {}).get("hostvars", {})
|
||||
targets = []
|
||||
for name in hosts:
|
||||
address = hostvars.get(name, {}).get("ansible_host")
|
||||
if not address:
|
||||
raise SystemExit(f"У {name} нет ansible_host")
|
||||
targets.append(address)
|
||||
if not targets:
|
||||
raise SystemExit("В группе netbird нет машин")
|
||||
print("Цели из inventory:", ", ".join(targets))
|
||||
for address in targets:
|
||||
subprocess.check_call(["ssh-keyscan", "-H", address], stdout=open(f"{__import__('os').environ['HOME']}/.ssh/known_hosts", "a"))
|
||||
PY
|
||||
|
||||
ansible-playbook /tmp/homelab-infra/services/netbird/playbook.yml \
|
||||
-i "${inventory}" \
|
||||
ansible-playbook playbooks/site.yml \
|
||||
-i inventories/prod/hosts.yml \
|
||||
--limit netbird \
|
||||
--private-key "${HOME}/.ssh/id_ed25519" \
|
||||
-e "netbird_letsencrypt_email=${NETBIRD_LETSENCRYPT_EMAIL}"
|
||||
Reference in new issue
Block a user