2026-04-03 08:12:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
ssh-keygen -t rsa -b 4096 -f /home/user/.ssh/id_rsa -N ""
|
|
|
|
|
|
|
|
|
|
mkdir -p /home/user/ansible
|
|
|
|
|
cd /home/user/ansible
|
|
|
|
|
python3 -m venv venv/ansible
|
|
|
|
|
source venv/ansible/bin/activate
|
|
|
|
|
mkdir -p inventories/production
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "[defaults]" > ansible.cfg
|
|
|
|
|
echo "inventory = inventories/production/hosts" >> ansible.cfg
|
|
|
|
|
echo "host_key_checking = false" >> ansible.cfg
|
|
|
|
|
echo "remote_user = root" >> ansible.cfg
|
|
|
|
|
echo "private_key_file = /root/.ssh/id_rsa" >> ansible.cfg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "all:" > inventories/production/hosts
|
|
|
|
|
echo " vars:" >> inventories/production/hosts
|
|
|
|
|
echo " ansible_user: user" >> inventories/production/hosts
|
|
|
|
|
echo " ansible_ssh_private_key_file: /home/user/.ssh/id_rsa" >> inventories/production/hosts
|
|
|
|
|
echo " ansible_ssh_common_args: '-o StrictHostKeyChecking=no'" >> inventories/production/hosts
|
|
|
|
|
echo " children:" >> inventories/production/hosts
|
|
|
|
|
echo " proxy:" >> inventories/production/hosts
|
|
|
|
|
echo " hosts:" >> inventories/production/hosts
|
|
|
|
|
echo " ha1-cod.au.team:" >> inventories/production/hosts
|
|
|
|
|
echo " ha2-cod.au.team:" >> inventories/production/hosts
|
|
|
|
|
echo " server:" >> inventories/production/hosts
|
|
|
|
|
echo " hosts:" >> inventories/production/hosts
|
|
|
|
|
echo " srv1-cod.au.team:" >> inventories/production/hosts
|
|
|
|
|
echo " srv2-cod.au.team:" >> inventories/production/hosts
|
|
|
|
|
echo " srv3-cod.au.team:" >> inventories/production/hosts
|
|
|
|
|
|
|
|
|
|
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@ha1-cod
|
|
|
|
|
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@ha2-cod
|
|
|
|
|
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@srv1-cod
|
|
|
|
|
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@srv2-cod
|
|
|
|
|
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@srv3-cod
|
|
|
|
|
|
|
|
|
|
ansible -i inventories/production/hosts -m ping all
|