Ansible Maintenance Guide
This document explains the current patch-management setup running from itvxwebansible and the procedures for routine maintenance.
1. Overview
- Control node:
itvxwebansible(Ansible Core 2.13.7). - Primary playbook:
/home/administrator/playbooks/update-upgrade.yml. - Target hosts grouped under meta-group
update_targets(children:beaulieu,cloud). - Automation runs via cron:
0 8 * * 3 /usr/bin/ansible-playbook -e @/home/administrator/vault/vault.yml /home/administrator/playbooks/update-upgrade.yml. - Slack notifications (success + failure) use vaulted credentials stored in
/home/administrator/vault/vault.yml.
2. Inventory Layout
- File:
/etc/ansible/hosts. - Groups:
beaulieu:itvxwebansible(local),itvxweb,itvxwebdmz,itvxwebstagingdmz.cloud:itwebcloudprod,itwebclouddatabase(accessed via bastion at137.184.161.76).update_targets: meta-group including bothbeaulieuandcloud.
2.1 Modify an Existing Host IP
- Edit
/etc/ansible/hosts(use sudo when necessary).shsudo nano /etc/ansible/hosts - Update the
ansible_host=value for the desired entry. - Test SSH access:sh
ssh <host-alias> - Verify Ansible connectivity:sh
ansible <group-or-host> -m ping -e @/home/administrator/vault/vault.yml
2.2 Update SSH Proxy or Keys
- Adjust
ansible_ssh_args,ansible_user, oransible_ssh_private_keyin/etc/ansible/hosts. - Store private keys in
~/.ssh/and keep permissions restrictive (chmod 600 ~/.ssh/id_rsa) so SSH accepts them.
3. Managing Credentials
- Sensitive values are stored in
/home/administrator/vault/vault.ymland protected by Ansible Vault (password file/etc/ansible/9d78b81a.txt).
3.1 Changing a Sudo Password
- Decrypt to a temp file (Ansible will prompt if the vault password file has moved):sh
ansible-vault decrypt /home/administrator/vault/vault.yml --output /tmp/vault_plain.yml --vault-password-file /etc/ansible/9d78b81a.txt - Update the relevant variable (e.g.,
master_passwordforbeaulieuhosts) and save the file. - Re-encrypt:sh
ansible-vault encrypt /tmp/vault_plain.yml --output /home/administrator/vault/vault.yml --vault-password-file /etc/ansible/9d78b81a.txt --encrypt-vault-id default rm /tmp/vault_plain.yml - Run a dry-run to confirm:sh
ansible-playbook /home/administrator/playbooks/update-upgrade.yml -e @/home/administrator/vault/vault.yml --limit update_targets --check
3.2 Rotating Slack Tokens
- Generate a new token at
https://api.slack.com/apps(reinstall the app if Slack asks for authorization). - Update
slack_bot_tokenin the vault (same process as above). - Optionally adjust
slack_channelorslack_username. - Trigger a dry-run to validate Slack notifications.
4. Adding or Removing Hosts
4.1 Add a Host
- Add inventory entry under the appropriate group in
/etc/ansible/hosts.ini[beaulieu] newhost ansible_host=10.0.0.10 ansible_ssh_private_key=~/.ssh/id_rsa # set permission with: chmod 600 ~/.ssh/id_rsa - If the host needs a proxy jump, include
ansible_ssh_argssimilar to existing cloud hosts. - Ensure required credentials are stored in the vault (e.g., add
master_passwordor host-specific sudo variables). - Test access and Ansible connectivity (
sshandansible -m ping). - Run the playbook in check mode limited to the new host:sh
ansible-playbook /home/administrator/playbooks/update-upgrade.yml -e @/home/administrator/vault/vault.yml --limit newhost --check
4.2 Remove a Host
- Comment or delete the host entry in
/etc/ansible/hosts. - Remove any host-specific secrets from the vault if they are no longer needed.
- Clean up SSH config entries (
~/.ssh/config) if present.
5. Running the Playbook Manually
- Dry-run (safe preview):sh
ansible-playbook /home/administrator/playbooks/update-upgrade.yml -e @/home/administrator/vault/vault.yml --limit update_targets --check - Full execution:sh
ansible-playbook /home/administrator/playbooks/update-upgrade.yml -e @/home/administrator/vault/vault.yml --limit update_targets - Limit to a subset (e.g., only cloud hosts):sh
ansible-playbook ... --limit cloud
6. Cron Automation
- Check the scheduled job:sh
crontab -l - To adjust schedule, edit the crontab entry (
crontab -e). - Monitor
/var/log/syslogor Slack notifications for run status.
7. Troubleshooting & Maintenance Tips
- Host key changes: Remove or update entries in
~/.ssh/known_hostsif SSH warns about mismatched keys (ssh-keygen -R hostname). - Proxy issues: Ensure the bastion (
137.184.161.76) is reachable when managing cloud hosts. - Slack errors:
missing_scopeorinvalid_authindicates the token needs updated permissions or rotation. - Failed tasks: Review Slack failure alerts; they include the task name, action, and JSON error output.
- Backups: Previous copies of
/etc/ansible/hostsmay exist with.pre_*.backupnaming—maintain or prune as needed.
