#!/bin/bash set -euo pipefail export HOME=/root LC_ALL=C.UTF-8 apt-get install -y ansible sshpass mkdir -p /etc/ansible /root/.ssh chmod 700 /root/.ssh test -f /root/.ssh/id_ed25519 || ssh-keygen -t ed25519 -N '' -f /root/.ssh/id_ed25519 export SSHPASS='P@ssw0rd' for item in sshuser@192.168.100.2:2027 student@192.168.100.34:22 net_admin@192.168.100.1:22 net_admin@192.168.254.0:22; do target=${item%:*}; port=${item##*:} sshpass -e ssh-copy-id -i /root/.ssh/id_ed25519.pub -o StrictHostKeyChecking=accept-new -p "$port" "$target" done cat > /etc/ansible/ansible.cfg <<'EOF' [defaults] inventory = /etc/ansible/hosts.yml interpreter_python = /usr/bin/python3 host_key_checking = True private_key_file = /root/.ssh/id_ed25519 EOF cat > /etc/ansible/hosts.yml <<'EOF' all: hosts: hq-srv: ansible_host: 192.168.100.2 ansible_user: sshuser ansible_port: 2027 hq-cli: ansible_host: 192.168.100.34 ansible_user: student hq-rtr: ansible_host: 192.168.100.1 ansible_user: net_admin br-rtr: ansible_host: 192.168.254.0 ansible_user: net_admin EOF cd /etc/ansible ansible all -m ping # The supplied task3 playbook writes locally; no root escalation on clients. mkdir -p /mnt/additional mountpoint -q /mnt/additional || mount -o ro /dev/sr0 /mnt/additional cp /mnt/additional/playbook/get_hostname_address.yml /etc/ansible/ cmp /mnt/additional/playbook/get_hostname_address.yml /etc/ansible/get_hostname_address.yml ansible-playbook /etc/ansible/get_hostname_address.yml cat /etc/ansible/PC-INFO/*.yml