feat: 重构Ansible playbooks目录结构并添加新功能
- 将playbooks按功能分类到不同目录(系统管理/安全/服务/监控/云服务) - 新增Traefik和Consul集群部署配置 - 添加Docker Swarm监控栈配置 - 实现自动化部署脚本 - 更新README文档说明新结构和使用方法
This commit is contained in:
72
ansible/playbooks/05-cloud/cloud-providers-update.yml
Normal file
72
ansible/playbooks/05-cloud/cloud-providers-update.yml
Normal file
@@ -0,0 +1,72 @@
|
||||
---
|
||||
- name: Cloud Providers System Update Playbook
|
||||
hosts: huawei,google,ditigalocean,aws
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
# Ubuntu/Debian 系统更新 (apt)
|
||||
- name: Update apt cache (Ubuntu/Debian)
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- name: Upgrade all packages (Ubuntu/Debian)
|
||||
apt:
|
||||
upgrade: yes
|
||||
autoremove: yes
|
||||
autoclean: yes
|
||||
when: ansible_os_family == "Debian"
|
||||
register: apt_upgrade_result
|
||||
|
||||
# AWS Linux 系统更新 (dnf)
|
||||
- name: Update dnf cache (AWS Linux/RHEL)
|
||||
dnf:
|
||||
update_cache: yes
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
- name: Upgrade all packages (AWS Linux/RHEL)
|
||||
dnf:
|
||||
name: "*"
|
||||
state: latest
|
||||
skip_broken: yes
|
||||
when: ansible_os_family == "RedHat"
|
||||
register: dnf_upgrade_result
|
||||
|
||||
# 显示升级结果
|
||||
- name: Display apt upgrade results
|
||||
debug:
|
||||
msg: "APT system upgrade completed. {{ apt_upgrade_result.changed }} packages were updated."
|
||||
when: ansible_os_family == "Debian" and apt_upgrade_result is defined
|
||||
|
||||
- name: Display dnf upgrade results
|
||||
debug:
|
||||
msg: "DNF system upgrade completed. {{ dnf_upgrade_result.changed }} packages were updated."
|
||||
when: ansible_os_family == "RedHat" and dnf_upgrade_result is defined
|
||||
|
||||
# 检查是否需要重启 (Ubuntu/Debian)
|
||||
- name: Check if reboot is required (Ubuntu/Debian)
|
||||
stat:
|
||||
path: /var/run/reboot-required
|
||||
register: debian_reboot_required
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
# 检查是否需要重启 (AWS Linux/RHEL)
|
||||
- name: Check if reboot is required (AWS Linux/RHEL)
|
||||
command: needs-restarting -r
|
||||
register: rhel_reboot_required
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
# 通知重启信息
|
||||
- name: Notify if reboot is required (Ubuntu/Debian)
|
||||
debug:
|
||||
msg: "System reboot is required to complete the update."
|
||||
when: ansible_os_family == "Debian" and debian_reboot_required.stat.exists is defined and debian_reboot_required.stat.exists
|
||||
|
||||
- name: Notify if reboot is required (AWS Linux/RHEL)
|
||||
debug:
|
||||
msg: "System reboot is required to complete the update."
|
||||
when: ansible_os_family == "RedHat" and rhel_reboot_required.rc == 1
|
||||
Reference in New Issue
Block a user