Add Ansible scripts for system management

This commit is contained in:
Semaphore Admin
2025-09-18 03:25:21 +00:00
commit 56a4994488
7 changed files with 183 additions and 0 deletions

10
ansible/ansible.cfg Normal file
View File

@@ -0,0 +1,10 @@
[defaults]
inventory = inventory.ini
host_key_checking = False
timeout = 30
gathering = smart
fact_caching = memory
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no
pipelining = True

8
ansible/inventory.ini Normal file
View File

@@ -0,0 +1,8 @@
[servers]
# 添加您的服务器信息,例如:
# server1 ansible_host=192.168.1.10 ansible_user=root
# server2 ansible_host=192.168.1.11 ansible_user=ubuntu ansible_become=yes
localhost ansible_connection=local
[all:vars]
ansible_ssh_common_args='-o StrictHostKeyChecking=no'

35
ansible/system-update.yml Normal file
View File

@@ -0,0 +1,35 @@
---
- name: System Update Playbook
hosts: all
become: yes
gather_facts: yes
tasks:
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600
when: ansible_os_family == "Debian"
- name: Upgrade all packages
apt:
upgrade: yes
autoremove: yes
autoclean: yes
when: ansible_os_family == "Debian"
register: upgrade_result
- name: Display upgrade results
debug:
msg: "System upgrade completed. {{ upgrade_result.changed }} packages were updated."
- name: Check if reboot is required
stat:
path: /var/run/reboot-required
register: reboot_required
when: ansible_os_family == "Debian"
- name: Notify if reboot is required
debug:
msg: "System reboot is required to complete the update."
when: reboot_required.stat.exists is defined and reboot_required.stat.exists