Add ansible and playbook to trigger upgrade
Some checks failed
Run nix flake check / flake-check (push) Failing after 27m26s
Periodic flake update / flake-update (push) Successful in 1m24s

This commit is contained in:
Torjus Håkestad 2025-02-07 00:28:05 +01:00
parent fbcb81291b
commit 002f934c70
Signed by: torjus
SSH Key Fingerprint: SHA256:KjAds8wHfD2mBYK2H815s/+ABcSdcIHUndwHEdSxml4
4 changed files with 60 additions and 0 deletions

View File

@ -32,6 +32,14 @@
config.allowUnfree = true;
};
};
allSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems =
f: nixpkgs.lib.genAttrs allSystems (system: f { pkgs = import nixpkgs { inherit system; }; });
in
{
nixosConfigurations = {
@ -297,5 +305,16 @@
];
};
};
devShells = forAllSystems (
{ pkgs }:
{
default = pkgs.mkShell {
packages = with pkgs; [
ansible
python3
];
};
}
);
};
}

31
inventory Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python
import json
import subprocess
IGNORED_HOSTS = [
"inc1",
"inc2",
"media1",
"nixos-test1",
"ns3",
"ns4",
"template1",
]
result = subprocess.run(["nix", "flake", "show", "--json"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
results = json.loads(result.stdout)
configs = results.get("nixosConfigurations")
hosts = [x for x in configs.keys() if x not in IGNORED_HOSTS]
output = {
"all": {
"hosts": hosts,
"vars": {
"ansible_python_interpreter": "/run/current-system/sw/bin/python3"
},
}
}
print(json.dumps(output))

View File

@ -0,0 +1,9 @@
---
- name: Trigger nixos-upgrade job on all hosts
hosts: all
remote_user: root
tasks:
- ansible.builtin.systemd_service:
name: nixos-upgrade.service
state: started

View File

@ -4,5 +4,6 @@
pkgs.git
pkgs.jq
pkgs.kitty.terminfo
pkgs.python3
];
}