3
0
forked from jakub/ansible
Files
ansible_fencl/test.yml
martin.fencl cb2099a802 test
2025-12-05 21:19:51 +01:00

57 lines
1.7 KiB
YAML

- name: Test connectivity from Semaphore container to Homarr VMs
hosts: localhost
gather_facts: false
vars:
# List of VMs you want to test
vm_targets:
- { ip: "192.168.69.253" }
- { ip: "192.168.69.254" }
# Credentials (ideálně z env/secret)
vm_user: "{{ lookup('env', 'VM_USER') | default('howard') }}"
vm_pass: "{{ lookup('env', 'VM_PASS') }}"
tasks:
- name: Ensure sshpass is installed (inside container) # install sshpass
ansible.builtin.apt:
name: sshpass
state: present
update_cache: yes
- name: Ping VM IPs from container # simple ICMP ping
ansible.builtin.command: "ping -c 2 {{ item.ip }}"
loop: "{{ vm_targets }}"
register: ping_results
ignore_errors: true
- name: Show ping results
ansible.builtin.debug:
msg: "Ping to {{ item.item.ip }} -> rc={{ item.rc }}, stdout={{ item.stdout }}"
loop: "{{ ping_results.results }}"
- name: Test SSH to VM with ssh (SSH key)
ansible.builtin.command:
argv:
- ssh
- -i
- /path/to/id_rsa # sem dej cestu k privátnímu klíči v kontejneru
- -o
- StrictHostKeyChecking=no
- -o
- ConnectTimeout=5
- "{{ vm_user }}@{{ item.ip }}"
- "echo OK-from-{{ item.ip }}"
loop: "{{ vm_targets }}"
register: ssh_results
ignore_errors: true
- name: Show SSH results
ansible.builtin.debug:
msg: |
SSH to {{ item.item.ip }}:
rc={{ item.rc }}
stdout={{ item.stdout }}
stderr={{ item.stderr }}
loop: "{{ ssh_results.results }}"