From c642a36406e0ca9ed70249c01e9fdf0a3871ab13 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Mon, 1 Jun 2026 23:09:25 +0300 Subject: [PATCH] Initial Ansible inventory and playbooks --- .gitignore | 6 ++++++ add-ssh-key.yml | 15 +++++++++++++++ ansible.cfg | 4 ++++ facts.yml | 16 ++++++++++++++++ inventory.ini | 8 ++++++++ 5 files changed, 49 insertions(+) create mode 100644 .gitignore create mode 100644 add-ssh-key.yml create mode 100644 ansible.cfg create mode 100644 facts.yml create mode 100644 inventory.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..645b937 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# local/private files +.env +.vault_pass +*.retry +keys/id_* +keys/*.pem diff --git a/add-ssh-key.yml b/add-ssh-key.yml new file mode 100644 index 0000000..fd51a1e --- /dev/null +++ b/add-ssh-key.yml @@ -0,0 +1,15 @@ +--- +- name: Add SSH public key to VM user + hosts: proxmox_vms + gather_facts: false + + vars: + target_user: vrubel + key_file: "{{ lookup('env', 'HOME') }}/.ssh/id_ed25519.pub" + + tasks: + - name: Add public key to authorized_keys + ansible.posix.authorized_key: + user: "{{ target_user }}" + state: present + key: "{{ lookup('file', key_file) }}" diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..b223f14 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,4 @@ +[defaults] +inventory = inventory.ini +interpreter_python = auto_silent +host_key_checking = True diff --git a/facts.yml b/facts.yml new file mode 100644 index 0000000..9c90f60 --- /dev/null +++ b/facts.yml @@ -0,0 +1,16 @@ +--- +- name: Show VM facts + hosts: proxmox_vms + gather_facts: true + + tasks: + - name: Print important facts + ansible.builtin.debug: + msg: + - "Host: {{ inventory_hostname }}" + - "Hostname: {{ ansible_facts[\"hostname\"] }}" + - "OS family: {{ ansible_facts[\"os_family\"] }}" + - "Distribution: {{ ansible_facts[\"distribution\"] }}" + - "Distribution version: {{ ansible_facts[\"distribution_version\"] }}" + - "Package manager: {{ ansible_facts[\"pkg_mgr\"] }}" + - "Python: {{ ansible_facts[\"python\"][\"executable\"] }}" diff --git a/inventory.ini b/inventory.ini new file mode 100644 index 0000000..01b8197 --- /dev/null +++ b/inventory.ini @@ -0,0 +1,8 @@ +[proxmox_vms] +nginx ansible_host=192.168.8.170 ansible_user=vrubel +docker-prod ansible_host=192.168.8.171 ansible_user=vrubel +fedoraXfce ansible_host=192.168.8.172 ansible_user=vrubel +hermes ansible_host=192.168.8.173 ansible_user=vrubel +docker-test ansible_host=192.168.8.174 ansible_user=vrubel +cicd ansible_host=192.168.8.175 ansible_user=vrubel +monitoring ansible_host=192.168.8.176 ansible_user=vrubel