forked from jakub/ansible
test
This commit is contained in:
58
test.yml
Normal file
58
test.yml
Normal file
@@ -0,0 +1,58 @@
|
||||
- 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 sshpass # real SSH test
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- sshpass
|
||||
- -e
|
||||
- ssh
|
||||
- -o
|
||||
- StrictHostKeyChecking=no
|
||||
- -o
|
||||
- ConnectTimeout=5
|
||||
- "{{ vm_user }}@{{ item.ip }}"
|
||||
- "echo OK-from-{{ item.ip }}"
|
||||
environment:
|
||||
SSHPASS: "{{ vm_pass }}"
|
||||
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 }}"
|
||||
Reference in New Issue
Block a user