Install #
Performed on Debian 12 (bookworm)
echo $UBUNTU_CODENAME
wget -O- "https://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=get&search=0x6125E2A8C77F2818FB7BD15B93C4A3FD7BB9C367" | sudo gpg --dearmour -o /usr/share/keyrings/ansible-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/ansible-archive-keyring.gpg] http://ppa.launchpad.net/ansible/ansible/ubuntu $UBUNTU_CODENAME main" | sudo tee /etc/apt/sources.list.d/ansible.list
sudo apt update && sudo apt install ansible
which ansible
ansible --version
Create inventory #
cd /etc/ansible
sudo nano hosts
ansible-inventory --list -y
Test that hosts are reachable #
# Confirm fingerprint of each SSH connection when connecting first time
ansible all -m ping
# Do ssh-copy-id on other servers that failed auto-login check
ssh-copy-id machine1.mylan.net
# Test individual host
ansible machine1.mylan.net -m ping
Create playbook for updating packages #
---
#apt-upgrade.yml
- hosts: apt
become: true
tasks:
- name: Update and upgrade apt packages
apt:
name: "*"
state: latest
#upgrade: yes
update_cache: yes
cache_valid_time: 86400 #One day
autoremove: yes
purge: true