feat: 添加Nomad集群监控与配置更新
fix(nomad): 修复服务器网络配置和重复配置问题 perf: 优化Podman与Nomad集成配置 refactor: 重构inventory文件结构 docs: 添加Telegraf监控部署文档 chore: 清理旧配置文件和脚本
This commit is contained in:
202
configuration/playbooks/add-warden-to-nomad-cluster.yml
Normal file
202
configuration/playbooks/add-warden-to-nomad-cluster.yml
Normal file
@@ -0,0 +1,202 @@
|
||||
---
|
||||
- name: Add Warden Server as Nomad Client to Cluster
|
||||
hosts: warden
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
vars:
|
||||
nomad_plugin_dir: "/opt/nomad/plugins"
|
||||
nomad_datacenter: "dc1"
|
||||
nomad_region: "global"
|
||||
nomad_servers:
|
||||
- "100.117.106.136:4647"
|
||||
- "100.116.80.94:4647"
|
||||
- "100.97.62.111:4647"
|
||||
- "100.116.112.45:4647"
|
||||
- "100.84.197.26:4647"
|
||||
|
||||
tasks:
|
||||
- name: 显示当前处理的节点
|
||||
debug:
|
||||
msg: "🔧 将 warden 服务器添加为 Nomad 客户端: {{ inventory_hostname }}"
|
||||
|
||||
- name: 检查 Nomad 是否已安装
|
||||
shell: which nomad || echo "not_found"
|
||||
register: nomad_check
|
||||
changed_when: false
|
||||
|
||||
- name: 下载并安装 Nomad
|
||||
block:
|
||||
- name: 下载 Nomad 1.10.5
|
||||
get_url:
|
||||
url: "https://releases.hashicorp.com/nomad/1.10.5/nomad_1.10.5_linux_amd64.zip"
|
||||
dest: "/tmp/nomad.zip"
|
||||
mode: '0644'
|
||||
|
||||
- name: 解压并安装 Nomad
|
||||
unarchive:
|
||||
src: "/tmp/nomad.zip"
|
||||
dest: "/usr/local/bin/"
|
||||
remote_src: yes
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
|
||||
- name: 清理临时文件
|
||||
file:
|
||||
path: "/tmp/nomad.zip"
|
||||
state: absent
|
||||
when: nomad_check.stdout == "not_found"
|
||||
|
||||
- name: 验证 Nomad 安装
|
||||
shell: nomad version
|
||||
register: nomad_version_output
|
||||
|
||||
- name: 创建 Nomad 配置目录
|
||||
file:
|
||||
path: /etc/nomad.d
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
|
||||
- name: 创建 Nomad 数据目录
|
||||
file:
|
||||
path: /opt/nomad/data
|
||||
state: directory
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0755'
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 创建 Nomad 插件目录
|
||||
file:
|
||||
path: "{{ nomad_plugin_dir }}"
|
||||
state: directory
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0755'
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 获取服务器 IP 地址
|
||||
shell: |
|
||||
ip route get 1.1.1.1 | grep -oP 'src \K\S+'
|
||||
register: server_ip_result
|
||||
changed_when: false
|
||||
|
||||
- name: 设置服务器 IP 变量
|
||||
set_fact:
|
||||
server_ip: "{{ server_ip_result.stdout }}"
|
||||
|
||||
- name: 停止 Nomad 服务(如果正在运行)
|
||||
systemd:
|
||||
name: nomad
|
||||
state: stopped
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 创建 Nomad 客户端配置文件
|
||||
copy:
|
||||
content: |
|
||||
# Nomad Client Configuration for warden
|
||||
datacenter = "{{ nomad_datacenter }}"
|
||||
data_dir = "/opt/nomad/data"
|
||||
log_level = "INFO"
|
||||
bind_addr = "{{ server_ip }}"
|
||||
|
||||
server {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
client {
|
||||
enabled = true
|
||||
servers = [
|
||||
{% for server in nomad_servers %}"{{ server }}"{% if not loop.last %}, {% endif %}{% endfor %}
|
||||
]
|
||||
}
|
||||
|
||||
plugin_dir = "{{ nomad_plugin_dir }}"
|
||||
|
||||
plugin "podman" {
|
||||
config {
|
||||
socket_path = "unix:///run/podman/podman.sock"
|
||||
volumes {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
consul {
|
||||
address = "127.0.0.1:8500"
|
||||
}
|
||||
dest: /etc/nomad.d/nomad.hcl
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
- name: 验证 Nomad 配置
|
||||
shell: nomad config validate /etc/nomad.d/nomad.hcl
|
||||
register: nomad_validate
|
||||
failed_when: nomad_validate.rc != 0
|
||||
|
||||
- name: 创建 Nomad systemd 服务文件
|
||||
copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Nomad
|
||||
Documentation=https://www.nomadproject.io/docs/
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
User=root
|
||||
Group=root
|
||||
ExecStart=/usr/local/bin/nomad agent -config=/etc/nomad.d
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
KillSignal=SIGINT
|
||||
TimeoutStopSec=5
|
||||
LimitNOFILE=65536
|
||||
LimitNPROC=32768
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
dest: /etc/systemd/system/nomad.service
|
||||
mode: '0644'
|
||||
|
||||
- name: 重新加载 systemd 配置
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
|
||||
- name: 启动并启用 Nomad 服务
|
||||
systemd:
|
||||
name: nomad
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: 等待 Nomad 服务启动
|
||||
wait_for:
|
||||
port: 4646
|
||||
host: "{{ server_ip }}"
|
||||
delay: 5
|
||||
timeout: 60
|
||||
|
||||
- name: 检查 Nomad 客户端状态
|
||||
shell: nomad node status -self
|
||||
register: nomad_node_status
|
||||
retries: 5
|
||||
delay: 5
|
||||
until: nomad_node_status.rc == 0
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示 Nomad 客户端配置结果
|
||||
debug:
|
||||
msg: |
|
||||
✅ warden 服务器已成功配置为 Nomad 客户端
|
||||
📦 Nomad 版本: {{ nomad_version_output.stdout.split('\n')[0] }}
|
||||
🌐 服务器 IP: {{ server_ip }}
|
||||
🏗️ 数据中心: {{ nomad_datacenter }}
|
||||
📊 客户端状态: {{ 'SUCCESS' if nomad_node_status.rc == 0 else 'PENDING' }}
|
||||
🚀 warden 现在是 Nomad 集群的一部分
|
||||
15
configuration/playbooks/check-podman-version.yml
Normal file
15
configuration/playbooks/check-podman-version.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: 检查 Podman 版本
|
||||
hosts: warden
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: 检查当前 Podman 版本
|
||||
shell: podman --version
|
||||
register: current_podman_version
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示当前版本
|
||||
debug:
|
||||
msg: "当前 Podman 版本: {{ current_podman_version.stdout if current_podman_version.rc == 0 else '未安装或无法获取' }}"
|
||||
22
configuration/playbooks/check-podman-versions.yml
Normal file
22
configuration/playbooks/check-podman-versions.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
- name: Check podman version on semaphore (local)
|
||||
hosts: semaphore
|
||||
connection: local
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Check podman version
|
||||
command: /usr/local/bin/podman --version
|
||||
register: podman_version
|
||||
- name: Display podman version
|
||||
debug:
|
||||
msg: "Podman version on {{ inventory_hostname }} is: {{ podman_version.stdout }}"
|
||||
|
||||
- name: Check podman version on other beijing nodes
|
||||
hosts: beijing:!semaphore
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Check podman version
|
||||
command: /usr/local/bin/podman --version
|
||||
register: podman_version
|
||||
- name: Display podman version
|
||||
debug:
|
||||
msg: "Podman version on {{ inventory_hostname }} is: {{ podman_version.stdout }}"
|
||||
@@ -56,21 +56,29 @@
|
||||
loop: "{{ alias_files.files }}"
|
||||
when: alias_files.files is defined
|
||||
|
||||
- name: Clear shell history to remove alias commands
|
||||
shell: |
|
||||
> /root/.bash_history
|
||||
> /root/.zsh_history
|
||||
history -c
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Unalias all current aliases
|
||||
shell: unalias -a
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Restart shell services
|
||||
shell: |
|
||||
pkill -f bash || true
|
||||
pkill -f zsh || true
|
||||
- name: Clear aliases from /etc/profile.d/aliases.sh
|
||||
ansible.builtin.file:
|
||||
path: /etc/profile.d/aliases.sh
|
||||
state: absent
|
||||
|
||||
- name: Clear aliases from /root/.bashrc
|
||||
ansible.builtin.lineinfile:
|
||||
path: /root/.bashrc
|
||||
state: absent
|
||||
regexp: "^alias "
|
||||
|
||||
- name: Clear aliases from /root/.bash_aliases
|
||||
ansible.builtin.file:
|
||||
path: /root/.bash_aliases
|
||||
state: absent
|
||||
|
||||
- name: Clear history
|
||||
ansible.builtin.command:
|
||||
cmd: > /root/.bash_history
|
||||
|
||||
- name: Restart shell to apply changes
|
||||
ansible.builtin.command:
|
||||
cmd: pkill -f bash || true
|
||||
|
||||
- name: Test network connectivity after clearing aliases
|
||||
shell: ping -c 2 8.8.8.8 || echo "Ping failed"
|
||||
|
||||
32
configuration/playbooks/clear-all-aliases.yml
Normal file
32
configuration/playbooks/clear-all-aliases.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
- name: Remove all aliases from user shell configuration files
|
||||
hosts: all
|
||||
become: yes
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Find all relevant shell configuration files
|
||||
find:
|
||||
paths: /home
|
||||
patterns: .bashrc, .bash_aliases, .profile
|
||||
register: shell_config_files
|
||||
|
||||
- name: Remove aliases from shell configuration files
|
||||
replace:
|
||||
path: "{{ item.path }}"
|
||||
regexp: '^alias .*'
|
||||
replace: ''
|
||||
loop: "{{ shell_config_files.files }}"
|
||||
when: shell_config_files.files is defined
|
||||
|
||||
- name: Remove functions from shell configuration files
|
||||
replace:
|
||||
path: "{{ item.path }}"
|
||||
regexp: '^function .*'
|
||||
replace: ''
|
||||
loop: "{{ shell_config_files.files }}"
|
||||
when: shell_config_files.files is defined
|
||||
|
||||
- name: Display completion message
|
||||
debug:
|
||||
msg: "All aliases and functions have been removed from user shell configuration files."
|
||||
47
configuration/playbooks/clear-proxy-settings.yml
Normal file
47
configuration/playbooks/clear-proxy-settings.yml
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
- name: Clear proxy settings from the system
|
||||
hosts: all
|
||||
become: yes
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Remove proxy environment file
|
||||
file:
|
||||
path: /root/mgmt/configuration/proxy.env
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Unset proxy environment variables
|
||||
shell: |
|
||||
unset http_proxy
|
||||
unset https_proxy
|
||||
unset HTTP_PROXY
|
||||
unset HTTPS_PROXY
|
||||
unset no_proxy
|
||||
unset NO_PROXY
|
||||
unset ALL_PROXY
|
||||
unset all_proxy
|
||||
unset DOCKER_BUILDKIT
|
||||
unset BUILDKIT_PROGRESS
|
||||
unset GIT_HTTP_PROXY
|
||||
unset GIT_HTTPS_PROXY
|
||||
unset CURL_PROXY
|
||||
unset WGET_PROXY
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Remove proxy settings from /etc/environment
|
||||
lineinfile:
|
||||
path: /etc/environment
|
||||
state: absent
|
||||
regexp: '^(http_proxy|https_proxy|no_proxy|ALL_PROXY|DOCKER_BUILDKIT|BUILDKIT_PROGRESS|GIT_HTTP_PROXY|GIT_HTTPS_PROXY|CURL_PROXY|WGET_PROXY)='
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Remove proxy settings from /etc/apt/apt.conf.d/proxy.conf
|
||||
file:
|
||||
path: /etc/apt/apt.conf.d/proxy.conf
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Display completion message
|
||||
debug:
|
||||
msg: "Proxy settings have been cleared from the system."
|
||||
22
configuration/playbooks/configure-nomad-sudo.yml
Normal file
22
configuration/playbooks/configure-nomad-sudo.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
- name: Configure NOPASSWD sudo for nomad user
|
||||
hosts: nomad_clients
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Ensure sudoers.d directory exists
|
||||
file:
|
||||
path: /etc/sudoers.d
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0750'
|
||||
|
||||
- name: Allow nomad user passwordless sudo for required commands
|
||||
copy:
|
||||
dest: /etc/sudoers.d/nomad
|
||||
content: |
|
||||
nomad ALL=(ALL) NOPASSWD: /usr/bin/apt, /usr/bin/systemctl, /bin/mkdir, /bin/chown, /bin/chmod, /bin/mv, /bin/sed, /usr/bin/tee, /usr/sbin/usermod, /usr/bin/unzip, /usr/bin/wget
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0440'
|
||||
validate: 'visudo -cf %s'
|
||||
@@ -11,7 +11,12 @@
|
||||
- name: 获取当前节点的 Tailscale IP
|
||||
shell: tailscale ip | head -1
|
||||
register: current_tailscale_ip
|
||||
failed_when: current_tailscale_ip.rc != 0
|
||||
changed_when: false
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 计算用于 Nomad 的地址(优先 Tailscale,回退到 inventory 或 ansible_host)
|
||||
set_fact:
|
||||
node_addr: "{{ (current_tailscale_ip.stdout | default('')) is match('^100\\.') | ternary((current_tailscale_ip.stdout | trim), (hostvars[inventory_hostname].tailscale_ip | default(ansible_host))) }}"
|
||||
|
||||
- name: 确保 Nomad 配置目录存在
|
||||
file:
|
||||
@@ -32,12 +37,12 @@
|
||||
data_dir = "/opt/nomad/data"
|
||||
log_level = "INFO"
|
||||
|
||||
bind_addr = "{{ current_tailscale_ip.stdout }}"
|
||||
bind_addr = "{{ node_addr }}"
|
||||
|
||||
addresses {
|
||||
http = "0.0.0.0"
|
||||
rpc = "{{ current_tailscale_ip.stdout }}"
|
||||
serf = "{{ current_tailscale_ip.stdout }}"
|
||||
http = "{{ node_addr }}"
|
||||
rpc = "{{ node_addr }}"
|
||||
serf = "{{ node_addr }}"
|
||||
}
|
||||
|
||||
ports {
|
||||
@@ -74,9 +79,10 @@
|
||||
}
|
||||
|
||||
consul {
|
||||
address = "{{ current_tailscale_ip.stdout }}:8500"
|
||||
address = "{{ node_addr }}:8500"
|
||||
}
|
||||
when: nomad_role == "server"
|
||||
notify: restart nomad
|
||||
|
||||
- name: 生成 Nomad 客户端配置(使用 Tailscale)
|
||||
copy:
|
||||
@@ -89,12 +95,12 @@
|
||||
data_dir = "/opt/nomad/data"
|
||||
log_level = "INFO"
|
||||
|
||||
bind_addr = "{{ current_tailscale_ip.stdout }}"
|
||||
bind_addr = "{{ node_addr }}"
|
||||
|
||||
addresses {
|
||||
http = "0.0.0.0"
|
||||
rpc = "{{ current_tailscale_ip.stdout }}"
|
||||
serf = "{{ current_tailscale_ip.stdout }}"
|
||||
http = "{{ node_addr }}"
|
||||
rpc = "{{ node_addr }}"
|
||||
serf = "{{ node_addr }}"
|
||||
}
|
||||
|
||||
ports {
|
||||
@@ -109,6 +115,7 @@
|
||||
|
||||
client {
|
||||
enabled = true
|
||||
network_interface = "tailscale0"
|
||||
|
||||
servers = [
|
||||
"100.116.158.95:4647", # semaphore
|
||||
@@ -128,9 +135,10 @@
|
||||
}
|
||||
|
||||
consul {
|
||||
address = "{{ current_tailscale_ip.stdout }}:8500"
|
||||
address = "{{ node_addr }}:8500"
|
||||
}
|
||||
when: nomad_role == "client"
|
||||
notify: restart nomad
|
||||
|
||||
- name: 检查 Nomad 二进制文件位置
|
||||
shell: which nomad || find /usr -name nomad 2>/dev/null | head -1
|
||||
@@ -154,7 +162,7 @@
|
||||
Type=notify
|
||||
User=root
|
||||
Group=root
|
||||
ExecStart={{ nomad_binary_path.stdout }} agent -config=/etc/nomad.d/nomad.hcl
|
||||
ExecStart=/snap/bin/nomad agent -config=/etc/nomad.d/nomad.hcl
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
@@ -185,7 +193,7 @@
|
||||
- name: 等待 Nomad 服务启动
|
||||
wait_for:
|
||||
port: 4646
|
||||
host: "{{ current_tailscale_ip.stdout }}"
|
||||
host: "{{ node_addr }}"
|
||||
delay: 5
|
||||
timeout: 30
|
||||
ignore_errors: yes
|
||||
@@ -199,7 +207,7 @@
|
||||
debug:
|
||||
msg: |
|
||||
✅ 节点 {{ inventory_hostname }} 配置完成
|
||||
🌐 Tailscale IP: {{ current_tailscale_ip.stdout }}
|
||||
🌐 使用地址: {{ node_addr }}
|
||||
🎯 角色: {{ nomad_role }}
|
||||
🔧 Nomad 二进制: {{ nomad_binary_path.stdout }}
|
||||
📊 服务状态: {{ 'active' if nomad_status.rc == 0 else 'failed' }}
|
||||
|
||||
115
configuration/playbooks/configure-podman-for-nomad.yml
Normal file
115
configuration/playbooks/configure-podman-for-nomad.yml
Normal file
@@ -0,0 +1,115 @@
|
||||
---
|
||||
- name: Configure Podman for Nomad Integration
|
||||
hosts: all
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: 显示当前处理的节点
|
||||
debug:
|
||||
msg: "🔧 正在为 Nomad 配置 Podman: {{ inventory_hostname }}"
|
||||
|
||||
- name: 确保 Podman 已安装
|
||||
package:
|
||||
name: podman
|
||||
state: present
|
||||
|
||||
- name: 启用并启动 Podman socket 服务
|
||||
systemd:
|
||||
name: podman.socket
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: 创建 Podman 系统配置目录
|
||||
file:
|
||||
path: /etc/containers
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: 配置 Podman 使用系统 socket
|
||||
copy:
|
||||
content: |
|
||||
[engine]
|
||||
# 使用系统级 socket 而不是用户级 socket
|
||||
active_service = "system"
|
||||
[engine.service_destinations]
|
||||
[engine.service_destinations.system]
|
||||
uri = "unix:///run/podman/podman.sock"
|
||||
dest: /etc/containers/containers.conf
|
||||
mode: '0644'
|
||||
|
||||
- name: 检查是否存在 nomad 用户
|
||||
getent:
|
||||
database: passwd
|
||||
key: nomad
|
||||
register: nomad_user_check
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 为 nomad 用户创建配置目录
|
||||
file:
|
||||
path: "/home/nomad/.config/containers"
|
||||
state: directory
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0755'
|
||||
when: nomad_user_check is succeeded
|
||||
|
||||
- name: 为 nomad 用户配置 Podman
|
||||
copy:
|
||||
content: |
|
||||
[engine]
|
||||
active_service = "system"
|
||||
[engine.service_destinations]
|
||||
[engine.service_destinations.system]
|
||||
uri = "unix:///run/podman/podman.sock"
|
||||
dest: /home/nomad/.config/containers/containers.conf
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0644'
|
||||
when: nomad_user_check is succeeded
|
||||
|
||||
- name: 将 nomad 用户添加到 podman 组
|
||||
user:
|
||||
name: nomad
|
||||
groups: podman
|
||||
append: yes
|
||||
when: nomad_user_check is succeeded
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 创建 podman 组(如果不存在)
|
||||
group:
|
||||
name: podman
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 设置 podman socket 目录权限
|
||||
file:
|
||||
path: /run/podman
|
||||
state: directory
|
||||
mode: '0755'
|
||||
group: podman
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 验证 Podman socket 权限
|
||||
file:
|
||||
path: /run/podman/podman.sock
|
||||
mode: '066'
|
||||
when: nomad_user_check is succeeded
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 验证 Podman 安装
|
||||
shell: podman --version
|
||||
register: podman_version
|
||||
|
||||
- name: 测试 Podman 功能
|
||||
shell: podman info
|
||||
register: podman_info
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示配置结果
|
||||
debug:
|
||||
msg: |
|
||||
✅ 节点 {{ inventory_hostname }} Podman 配置完成
|
||||
📦 Podman 版本: {{ podman_version.stdout }}
|
||||
🐳 Podman 状态: {{ 'SUCCESS' if podman_info.rc == 0 else 'WARNING' }}
|
||||
👤 Nomad 用户: {{ 'FOUND' if nomad_user_check is succeeded else 'NOT FOUND' }}
|
||||
24
configuration/playbooks/debug-nomad-germany.yml
Normal file
24
configuration/playbooks/debug-nomad-germany.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
- name: Debug Nomad service on germany
|
||||
hosts: germany
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Get Nomad service status
|
||||
command: systemctl status nomad.service --no-pager -l
|
||||
register: nomad_status
|
||||
ignore_errors: true
|
||||
|
||||
- name: Get Nomad service journal
|
||||
command: journalctl -xeu nomad.service --no-pager -n 100
|
||||
register: nomad_journal
|
||||
ignore_errors: true
|
||||
|
||||
- name: Display debug information
|
||||
debug:
|
||||
msg: |
|
||||
--- Nomad Service Status ---
|
||||
{{ nomad_status.stdout }}
|
||||
{{ nomad_status.stderr }}
|
||||
|
||||
--- Nomad Service Journal ---
|
||||
{{ nomad_journal.stdout }}
|
||||
{{ nomad_journal.stderr }}
|
||||
12
configuration/playbooks/debug-syd.yml
Normal file
12
configuration/playbooks/debug-syd.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
- name: Distribute new podman binary to syd
|
||||
hosts: syd
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Copy new podman binary to /usr/local/bin
|
||||
copy:
|
||||
src: /root/mgmt/configuration/podman-remote-static-linux_amd64
|
||||
dest: /usr/local/bin/podman
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
become: yes
|
||||
76
configuration/playbooks/distribute-podman-driver.yml
Normal file
76
configuration/playbooks/distribute-podman-driver.yml
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
- name: Distribute Nomad Podman Driver to all nodes
|
||||
hosts: nomad_cluster
|
||||
become: yes
|
||||
vars:
|
||||
nomad_user: nomad
|
||||
nomad_data_dir: /opt/nomad/data
|
||||
nomad_plugins_dir: "{{ nomad_data_dir }}/plugins"
|
||||
|
||||
tasks:
|
||||
- name: Stop Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: stopped
|
||||
|
||||
- name: Create plugins directory
|
||||
file:
|
||||
path: "{{ nomad_plugins_dir }}"
|
||||
state: directory
|
||||
owner: "{{ nomad_user }}"
|
||||
group: "{{ nomad_user }}"
|
||||
mode: '0755'
|
||||
|
||||
- name: Copy Nomad Podman driver from local
|
||||
copy:
|
||||
src: /tmp/nomad-driver-podman
|
||||
dest: "{{ nomad_plugins_dir }}/nomad-driver-podman"
|
||||
owner: "{{ nomad_user }}"
|
||||
group: "{{ nomad_user }}"
|
||||
mode: '0755'
|
||||
|
||||
- name: Update Nomad configuration for plugin directory
|
||||
lineinfile:
|
||||
path: /etc/nomad.d/nomad.hcl
|
||||
regexp: '^plugin_dir'
|
||||
line: 'plugin_dir = "{{ nomad_plugins_dir }}"'
|
||||
insertafter: 'data_dir = "/opt/nomad/data"'
|
||||
|
||||
- name: Ensure Podman is installed
|
||||
package:
|
||||
name: podman
|
||||
state: present
|
||||
|
||||
- name: Enable Podman socket
|
||||
systemd:
|
||||
name: podman.socket
|
||||
enabled: yes
|
||||
state: started
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Start Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Wait for Nomad to be ready
|
||||
wait_for:
|
||||
port: 4646
|
||||
host: localhost
|
||||
delay: 10
|
||||
timeout: 60
|
||||
|
||||
- name: Wait for plugins to load
|
||||
pause:
|
||||
seconds: 15
|
||||
|
||||
- name: Check driver status
|
||||
shell: |
|
||||
/usr/local/bin/nomad node status -self | grep -A 10 "Driver Status" || /usr/bin/nomad node status -self | grep -A 10 "Driver Status"
|
||||
register: driver_status
|
||||
failed_when: false
|
||||
|
||||
- name: Display driver status
|
||||
debug:
|
||||
var: driver_status.stdout_lines
|
||||
12
configuration/playbooks/distribute-podman-germany.yml
Normal file
12
configuration/playbooks/distribute-podman-germany.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
- name: Distribute new podman binary to germany
|
||||
hosts: germany
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Copy new podman binary to /usr/local/bin
|
||||
copy:
|
||||
src: /root/mgmt/configuration/podman-remote-static-linux_amd64
|
||||
dest: /usr/local/bin/podman
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
become: yes
|
||||
12
configuration/playbooks/distribute-podman.yml
Normal file
12
configuration/playbooks/distribute-podman.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
- name: Distribute new podman binary to specified nomad_clients
|
||||
hosts: nomadlxc,hcp,huawei,ditigalocean
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Copy new podman binary to /usr/local/bin
|
||||
copy:
|
||||
src: /root/mgmt/configuration/podman-remote-static-linux_amd64
|
||||
dest: /usr/local/bin/podman
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
become: yes
|
||||
25
configuration/playbooks/ensure-nomad-user.yml
Normal file
25
configuration/playbooks/ensure-nomad-user.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
- name: Ensure nomad user and plugin directory exist
|
||||
hosts: nomad_clients
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Ensure nomad group exists
|
||||
group:
|
||||
name: nomad
|
||||
state: present
|
||||
|
||||
- name: Ensure nomad user exists
|
||||
user:
|
||||
name: nomad
|
||||
group: nomad
|
||||
shell: /usr/sbin/nologin
|
||||
system: yes
|
||||
create_home: no
|
||||
|
||||
- name: Ensure plugin directory exists with correct ownership
|
||||
file:
|
||||
path: /opt/nomad/data/plugins
|
||||
state: directory
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0755'
|
||||
16
configuration/playbooks/fix-apt-errors.yml
Normal file
16
configuration/playbooks/fix-apt-errors.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
- name: Debug apt repository issues
|
||||
hosts: beijing:children
|
||||
become: yes
|
||||
ignore_unreachable: yes
|
||||
tasks:
|
||||
- name: Run apt-get update to capture error
|
||||
ansible.builtin.shell: apt-get update
|
||||
register: apt_update_result
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
- name: Display apt-get update stderr
|
||||
ansible.builtin.debug:
|
||||
var: apt_update_result.stderr
|
||||
verbosity: 2
|
||||
126
configuration/playbooks/fix-duplicate-podman-config.yml
Normal file
126
configuration/playbooks/fix-duplicate-podman-config.yml
Normal file
@@ -0,0 +1,126 @@
|
||||
---
|
||||
- name: Fix duplicate Podman configuration in Nomad
|
||||
hosts: nomad_cluster
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Stop Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: stopped
|
||||
|
||||
- name: Backup current configuration
|
||||
copy:
|
||||
src: /etc/nomad.d/nomad.hcl
|
||||
dest: /etc/nomad.d/nomad.hcl.backup-duplicate-fix
|
||||
remote_src: yes
|
||||
|
||||
- name: Read current configuration
|
||||
slurp:
|
||||
src: /etc/nomad.d/nomad.hcl
|
||||
register: current_config
|
||||
|
||||
- name: Create clean configuration for clients
|
||||
copy:
|
||||
content: |
|
||||
datacenter = "{{ nomad_datacenter }}"
|
||||
region = "{{ nomad_region }}"
|
||||
data_dir = "/opt/nomad/data"
|
||||
bind_addr = "{{ tailscale_ip }}"
|
||||
|
||||
server {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
client {
|
||||
enabled = true
|
||||
servers = ["100.116.158.95:4647", "100.117.106.136:4647", "100.86.141.112:4647", "100.81.26.3:4647", "100.103.147.94:4647"]
|
||||
}
|
||||
|
||||
ui {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
addresses {
|
||||
http = "0.0.0.0"
|
||||
rpc = "{{ tailscale_ip }}"
|
||||
serf = "{{ tailscale_ip }}"
|
||||
}
|
||||
|
||||
ports {
|
||||
http = 4646
|
||||
rpc = 4647
|
||||
serf = 4648
|
||||
}
|
||||
|
||||
plugin "podman" {
|
||||
config {
|
||||
socket_path = "unix:///run/podman/podman.sock"
|
||||
volumes {
|
||||
enabled = true
|
||||
}
|
||||
recover_stopped = true
|
||||
}
|
||||
}
|
||||
|
||||
consul {
|
||||
auto_advertise = false
|
||||
server_auto_join = false
|
||||
client_auto_join = false
|
||||
}
|
||||
|
||||
log_level = "INFO"
|
||||
enable_syslog = true
|
||||
dest: /etc/nomad.d/nomad.hcl
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0640'
|
||||
when: nomad_role == "client"
|
||||
|
||||
- name: Ensure Podman is installed
|
||||
package:
|
||||
name: podman
|
||||
state: present
|
||||
|
||||
- name: Enable and start Podman socket
|
||||
systemd:
|
||||
name: podman.socket
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Set proper permissions on Podman socket
|
||||
file:
|
||||
path: /run/podman/podman.sock
|
||||
mode: '0666'
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Validate Nomad configuration
|
||||
shell: /usr/local/bin/nomad config validate /etc/nomad.d/nomad.hcl || /usr/bin/nomad config validate /etc/nomad.d/nomad.hcl
|
||||
register: config_validation
|
||||
failed_when: config_validation.rc != 0
|
||||
|
||||
- name: Start Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Wait for Nomad to be ready
|
||||
wait_for:
|
||||
port: 4646
|
||||
host: localhost
|
||||
delay: 10
|
||||
timeout: 60
|
||||
|
||||
- name: Wait for drivers to load
|
||||
pause:
|
||||
seconds: 20
|
||||
|
||||
- name: Check driver status
|
||||
shell: |
|
||||
/usr/local/bin/nomad node status -self | grep -A 10 "Driver Status" || /usr/bin/nomad node status -self | grep -A 10 "Driver Status"
|
||||
register: driver_status
|
||||
failed_when: false
|
||||
|
||||
- name: Display driver status
|
||||
debug:
|
||||
var: driver_status.stdout_lines
|
||||
34
configuration/playbooks/fix-hashicorp-apt-source.yml
Normal file
34
configuration/playbooks/fix-hashicorp-apt-source.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
- name: 直接复制正确的 HashiCorp APT 源配置
|
||||
hosts: nomad_cluster
|
||||
become: yes
|
||||
|
||||
tasks:
|
||||
- name: 备份现有的 HashiCorp APT 源配置(如果存在)
|
||||
copy:
|
||||
src: "/etc/apt/sources.list.d/hashicorp.list"
|
||||
dest: "/etc/apt/sources.list.d/hashicorp.list.backup-{{ ansible_date_time.epoch }}"
|
||||
remote_src: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 创建正确的 HashiCorp APT 源配置
|
||||
copy:
|
||||
content: "deb [trusted=yes] http://apt.releases.hashicorp.com bookworm main\n"
|
||||
dest: "/etc/apt/sources.list.d/hashicorp.list"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
- name: 更新 APT 缓存
|
||||
apt:
|
||||
update_cache: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 验证配置
|
||||
command: cat /etc/apt/sources.list.d/hashicorp.list
|
||||
register: config_check
|
||||
changed_when: false
|
||||
|
||||
- name: 显示配置内容
|
||||
debug:
|
||||
msg: "HashiCorp APT 源配置: {{ config_check.stdout }}"
|
||||
98
configuration/playbooks/fix-nomad-cluster.yml
Normal file
98
configuration/playbooks/fix-nomad-cluster.yml
Normal file
@@ -0,0 +1,98 @@
|
||||
---
|
||||
- name: Fix Nomad Cluster Configuration
|
||||
hosts: nomad_servers
|
||||
become: yes
|
||||
vars:
|
||||
nomad_servers_list:
|
||||
- "100.116.158.95" # semaphore
|
||||
- "100.103.147.94" # ash2e
|
||||
- "100.81.26.3" # ash1d
|
||||
- "100.90.159.68" # ch2
|
||||
- "{{ ansible_default_ipv4.address }}" # ch3 (will be determined dynamically)
|
||||
|
||||
tasks:
|
||||
- name: Stop Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: stopped
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Create nomad user
|
||||
user:
|
||||
name: nomad
|
||||
system: yes
|
||||
shell: /bin/false
|
||||
home: /opt/nomad
|
||||
create_home: no
|
||||
|
||||
- name: Create Nomad configuration directory
|
||||
file:
|
||||
path: /etc/nomad.d
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Create Nomad data directory
|
||||
file:
|
||||
path: /opt/nomad/data
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: nomad
|
||||
group: nomad
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Create Nomad log directory
|
||||
file:
|
||||
path: /var/log/nomad
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: nomad
|
||||
group: nomad
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Generate Nomad server configuration
|
||||
template:
|
||||
src: nomad-server.hcl.j2
|
||||
dest: /etc/nomad.d/nomad.hcl
|
||||
mode: '0644'
|
||||
notify: restart nomad
|
||||
|
||||
- name: Create Nomad systemd service file
|
||||
copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Nomad
|
||||
Documentation=https://www.nomadproject.io/
|
||||
Requires=network-online.target
|
||||
After=network-online.target
|
||||
ConditionFileNotEmpty=/etc/nomad.d/nomad.hcl
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
User=nomad
|
||||
Group=nomad
|
||||
ExecStart=/usr/bin/nomad agent -config=/etc/nomad.d/nomad.hcl
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
LimitNOFILE=65536
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
dest: /etc/systemd/system/nomad.service
|
||||
mode: '0644'
|
||||
|
||||
- name: Reload systemd daemon
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
|
||||
- name: Enable and start Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
handlers:
|
||||
- name: restart nomad
|
||||
systemd:
|
||||
name: nomad
|
||||
state: restarted
|
||||
109
configuration/playbooks/fix-server-config.yml
Normal file
109
configuration/playbooks/fix-server-config.yml
Normal file
@@ -0,0 +1,109 @@
|
||||
---
|
||||
- name: Fix Nomad server configuration
|
||||
hosts: nomad_servers
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Stop Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: stopped
|
||||
|
||||
- name: Backup current configuration
|
||||
copy:
|
||||
src: /etc/nomad.d/nomad.hcl
|
||||
dest: /etc/nomad.d/nomad.hcl.backup-server-fix
|
||||
remote_src: yes
|
||||
|
||||
- name: Create clean server configuration
|
||||
copy:
|
||||
content: |
|
||||
datacenter = "{{ nomad_datacenter }}"
|
||||
region = "{{ nomad_region }}"
|
||||
data_dir = "/opt/nomad/data"
|
||||
bind_addr = "{{ ansible_default_ipv4.address }}"
|
||||
|
||||
server {
|
||||
enabled = true
|
||||
bootstrap_expect = {{ nomad_bootstrap_expect }}
|
||||
encrypt = "{{ nomad_encrypt_key }}"
|
||||
|
||||
retry_join = [
|
||||
"100.116.158.95",
|
||||
"100.103.147.94",
|
||||
"100.81.26.3",
|
||||
"100.90.159.68",
|
||||
"100.86.141.112"
|
||||
]
|
||||
}
|
||||
|
||||
client {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
ui {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
addresses {
|
||||
http = "0.0.0.0"
|
||||
rpc = "{{ ansible_default_ipv4.address }}"
|
||||
serf = "{{ ansible_default_ipv4.address }}"
|
||||
}
|
||||
|
||||
ports {
|
||||
http = 4646
|
||||
rpc = 4647
|
||||
serf = 4648
|
||||
}
|
||||
|
||||
plugin "podman" {
|
||||
config {
|
||||
socket_path = "unix:///run/podman/podman.sock"
|
||||
volumes {
|
||||
enabled = true
|
||||
}
|
||||
recover_stopped = true
|
||||
}
|
||||
}
|
||||
|
||||
consul {
|
||||
auto_advertise = false
|
||||
server_auto_join = false
|
||||
client_auto_join = false
|
||||
}
|
||||
|
||||
log_level = "INFO"
|
||||
log_file = "/var/log/nomad/nomad.log"
|
||||
dest: /etc/nomad.d/nomad.hcl
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0640'
|
||||
|
||||
- name: Ensure Podman is installed
|
||||
package:
|
||||
name: podman
|
||||
state: present
|
||||
|
||||
- name: Enable and start Podman socket
|
||||
systemd:
|
||||
name: podman.socket
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Validate Nomad configuration
|
||||
shell: /usr/local/bin/nomad config validate /etc/nomad.d/nomad.hcl || /usr/bin/nomad config validate /etc/nomad.d/nomad.hcl
|
||||
register: config_validation
|
||||
failed_when: config_validation.rc != 0
|
||||
|
||||
- name: Start Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Wait for Nomad to be ready
|
||||
wait_for:
|
||||
port: 4646
|
||||
host: localhost
|
||||
delay: 10
|
||||
timeout: 60
|
||||
103
configuration/playbooks/fix-server-network-config.yml
Normal file
103
configuration/playbooks/fix-server-network-config.yml
Normal file
@@ -0,0 +1,103 @@
|
||||
---
|
||||
- name: Fix Nomad server network configuration
|
||||
hosts: nomad_servers
|
||||
become: yes
|
||||
vars:
|
||||
server_ips:
|
||||
semaphore: "100.116.158.95"
|
||||
ash2e: "100.103.147.94"
|
||||
ash1d: "100.81.26.3"
|
||||
ch2: "100.90.159.68"
|
||||
ch3: "100.86.141.112"
|
||||
tasks:
|
||||
- name: Stop Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: stopped
|
||||
|
||||
- name: Get server IP for this host
|
||||
set_fact:
|
||||
server_ip: "{{ server_ips[inventory_hostname] }}"
|
||||
|
||||
- name: Create corrected server configuration
|
||||
copy:
|
||||
content: |
|
||||
datacenter = "{{ nomad_datacenter }}"
|
||||
region = "{{ nomad_region }}"
|
||||
data_dir = "/opt/nomad/data"
|
||||
bind_addr = "{{ server_ip }}"
|
||||
|
||||
server {
|
||||
enabled = true
|
||||
bootstrap_expect = {{ nomad_bootstrap_expect }}
|
||||
encrypt = "{{ nomad_encrypt_key }}"
|
||||
|
||||
retry_join = [
|
||||
"100.116.158.95",
|
||||
"100.103.147.94",
|
||||
"100.81.26.3",
|
||||
"100.90.159.68",
|
||||
"100.86.141.112"
|
||||
]
|
||||
}
|
||||
|
||||
client {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
ui {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
addresses {
|
||||
http = "0.0.0.0"
|
||||
rpc = "{{ server_ip }}"
|
||||
serf = "{{ server_ip }}"
|
||||
}
|
||||
|
||||
ports {
|
||||
http = 4646
|
||||
rpc = 4647
|
||||
serf = 4648
|
||||
}
|
||||
|
||||
plugin "podman" {
|
||||
config {
|
||||
socket_path = "unix:///run/podman/podman.sock"
|
||||
volumes {
|
||||
enabled = true
|
||||
}
|
||||
recover_stopped = true
|
||||
}
|
||||
}
|
||||
|
||||
consul {
|
||||
auto_advertise = false
|
||||
server_auto_join = false
|
||||
client_auto_join = false
|
||||
}
|
||||
|
||||
log_level = "INFO"
|
||||
log_file = "/var/log/nomad/nomad.log"
|
||||
dest: /etc/nomad.d/nomad.hcl
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0640'
|
||||
|
||||
- name: Validate Nomad configuration
|
||||
shell: /usr/local/bin/nomad config validate /etc/nomad.d/nomad.hcl || /usr/bin/nomad config validate /etc/nomad.d/nomad.hcl
|
||||
register: config_validation
|
||||
failed_when: config_validation.rc != 0
|
||||
|
||||
- name: Start Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Wait for Nomad to be ready
|
||||
wait_for:
|
||||
port: 4646
|
||||
host: localhost
|
||||
delay: 10
|
||||
timeout: 60
|
||||
39
configuration/playbooks/fix-warden-compose.yml
Normal file
39
configuration/playbooks/fix-warden-compose.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
- name: Fix Warden docker-compose.yml
|
||||
hosts: warden
|
||||
become: yes
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: Ensure /opt/warden directory exists
|
||||
file:
|
||||
path: /opt/warden
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
|
||||
- name: Create or update docker-compose.yml with correct indentation
|
||||
copy:
|
||||
dest: /opt/warden/docker-compose.yml
|
||||
content: |
|
||||
services:
|
||||
vaultwarden:
|
||||
image: hub.git4ta.fun/vaultwarden/server:latest
|
||||
security_opt:
|
||||
- "seccomp=unconfined"
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./data:/data
|
||||
ports:
|
||||
- "980:80"
|
||||
restart: always
|
||||
networks:
|
||||
- vaultwarden_network
|
||||
|
||||
networks:
|
||||
vaultwarden_network:
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
67
configuration/playbooks/hack-podman-upgrade.yml
Normal file
67
configuration/playbooks/hack-podman-upgrade.yml
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
- name: 强制升级 Podman 到最新版本
|
||||
hosts: warden
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: 检查当前 Podman 版本
|
||||
shell: podman --version
|
||||
register: current_podman_version
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示当前版本
|
||||
debug:
|
||||
msg: "升级前版本: {{ current_podman_version.stdout if current_podman_version.rc == 0 else '未安装' }}"
|
||||
|
||||
- name: 卸载现有 Podman
|
||||
shell: apt-get remove -y --purge podman* containerd* runc*
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 清理残留配置
|
||||
shell: |
|
||||
rm -rf /etc/containers
|
||||
rm -rf /usr/share/containers
|
||||
rm -rf /var/lib/containers
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 直接下载并安装最新版Podman二进制文件
|
||||
shell: |
|
||||
# 清理可能存在的旧版本
|
||||
rm -f /tmp/podman-latest.tar.gz
|
||||
rm -f /usr/local/bin/podman
|
||||
|
||||
# 获取最新版本号
|
||||
LATEST_VERSION="v5.6.1" # 硬编码最新版本避免网络问题
|
||||
echo "安装版本: $LATEST_VERSION"
|
||||
|
||||
# 使用GitHub镜像站点下载二进制文件
|
||||
echo "使用GitHub镜像站点下载..."
|
||||
wget -O /tmp/podman-latest.tar.gz "https://gh.git4ta.fun/github.com/containers/podman/releases/download/${LATEST_VERSION}/podman-linux-static-amd64.tar.gz"
|
||||
|
||||
# 检查文件是否下载成功,如果失败尝试直接下载
|
||||
if [ ! -f /tmp/podman-latest.tar.gz ]; then
|
||||
echo "镜像下载失败,尝试直接下载..."
|
||||
wget -O /tmp/podman-latest.tar.gz "https://github.com/containers/podman/releases/download/${LATEST_VERSION}/podman-linux-static-amd64.tar.gz"
|
||||
fi
|
||||
|
||||
# 解压并安装
|
||||
tar -xzf /tmp/podman-latest.tar.gz -C /usr/local/bin/ --strip-components=1
|
||||
chmod +x /usr/local/bin/podman
|
||||
|
||||
# 更新PATH
|
||||
echo 'export PATH=/usr/local/bin:$PATH' >> /etc/profile
|
||||
. /etc/profile
|
||||
|
||||
# 验证安装
|
||||
/usr/local/bin/podman --version
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 验证安装结果
|
||||
shell: podman --version
|
||||
register: new_podman_version
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示最终版本
|
||||
debug:
|
||||
msg: "升级后版本: {{ new_podman_version.stdout if new_podman_version.rc == 0 else '安装失败' }}"
|
||||
@@ -0,0 +1,161 @@
|
||||
---
|
||||
- name: Install and Configure Nomad Podman Driver on Client Nodes
|
||||
hosts: nomad_clients
|
||||
become: yes
|
||||
vars:
|
||||
nomad_plugin_dir: "/opt/nomad/plugins"
|
||||
|
||||
tasks:
|
||||
- name: Create backup directory with timestamp
|
||||
set_fact:
|
||||
backup_dir: "/root/backup/{{ ansible_date_time.date }}_{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}{{ ansible_date_time.second }}"
|
||||
|
||||
- name: Create backup directory
|
||||
file:
|
||||
path: "{{ backup_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Backup current Nomad configuration
|
||||
copy:
|
||||
src: /etc/nomad.d/nomad.hcl
|
||||
dest: "{{ backup_dir }}/nomad.hcl.backup"
|
||||
remote_src: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Backup current apt sources
|
||||
shell: |
|
||||
cp -r /etc/apt/sources.list* {{ backup_dir }}/
|
||||
dpkg --get-selections > {{ backup_dir }}/installed_packages.txt
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Create temporary directory for apt
|
||||
file:
|
||||
path: /tmp/apt-temp
|
||||
state: directory
|
||||
mode: '1777'
|
||||
|
||||
- name: Download HashiCorp GPG key
|
||||
get_url:
|
||||
url: https://apt.releases.hashicorp.com/gpg
|
||||
dest: /tmp/hashicorp.gpg
|
||||
mode: '0644'
|
||||
environment:
|
||||
TMPDIR: /tmp/apt-temp
|
||||
|
||||
- name: Install HashiCorp GPG key
|
||||
shell: |
|
||||
gpg --dearmor < /tmp/hashicorp.gpg > /usr/share/keyrings/hashicorp-archive-keyring.gpg
|
||||
environment:
|
||||
TMPDIR: /tmp/apt-temp
|
||||
|
||||
- name: Add HashiCorp repository
|
||||
lineinfile:
|
||||
path: /etc/apt/sources.list.d/hashicorp.list
|
||||
line: "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main"
|
||||
create: yes
|
||||
mode: '0644'
|
||||
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
environment:
|
||||
TMPDIR: /tmp/apt-temp
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Install nomad-driver-podman
|
||||
apt:
|
||||
name: nomad-driver-podman
|
||||
state: present
|
||||
environment:
|
||||
TMPDIR: /tmp/apt-temp
|
||||
|
||||
- name: Create Nomad plugin directory
|
||||
file:
|
||||
path: "{{ nomad_plugin_dir }}"
|
||||
state: directory
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0755'
|
||||
|
||||
- name: Create symlink for nomad-driver-podman in plugin directory
|
||||
file:
|
||||
src: /usr/bin/nomad-driver-podman
|
||||
dest: "{{ nomad_plugin_dir }}/nomad-driver-podman"
|
||||
state: link
|
||||
owner: nomad
|
||||
group: nomad
|
||||
|
||||
- name: Get server IP address
|
||||
shell: |
|
||||
ip route get 1.1.1.1 | grep -oP 'src \K\S+'
|
||||
register: server_ip_result
|
||||
changed_when: false
|
||||
|
||||
- name: Set server IP fact
|
||||
set_fact:
|
||||
server_ip: "{{ server_ip_result.stdout }}"
|
||||
|
||||
- name: Stop Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: stopped
|
||||
|
||||
- name: Create updated Nomad client configuration
|
||||
copy:
|
||||
content: |
|
||||
datacenter = "{{ nomad_datacenter }}"
|
||||
data_dir = "/opt/nomad/data"
|
||||
log_level = "INFO"
|
||||
bind_addr = "{{ server_ip }}"
|
||||
|
||||
server {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
client {
|
||||
enabled = true
|
||||
servers = ["100.117.106.136:4647", "100.116.80.94:4647", "100.97.62.111:4647", "100.116.112.45:4647", "100.84.197.26:4647"]
|
||||
}
|
||||
|
||||
plugin_dir = "{{ nomad_plugin_dir }}"
|
||||
|
||||
plugin "nomad-driver-podman" {
|
||||
config {
|
||||
volumes {
|
||||
enabled = true
|
||||
}
|
||||
recover_stopped = true
|
||||
}
|
||||
}
|
||||
|
||||
consul {
|
||||
address = "127.0.0.1:8500"
|
||||
}
|
||||
dest: /etc/nomad.d/nomad.hcl
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0640'
|
||||
backup: yes
|
||||
|
||||
- name: Validate Nomad configuration
|
||||
shell: nomad config validate /etc/nomad.d/nomad.hcl
|
||||
register: nomad_validate
|
||||
failed_when: nomad_validate.rc != 0
|
||||
|
||||
- name: Start Nomad service
|
||||
systemd:
|
||||
name: nomad
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Wait for Nomad to be ready
|
||||
wait_for:
|
||||
port: 4646
|
||||
host: "{{ server_ip }}"
|
||||
delay: 5
|
||||
timeout: 60
|
||||
|
||||
- name: Display backup location
|
||||
debug:
|
||||
msg: "Backup created at: {{ backup_dir }}"
|
||||
218
configuration/playbooks/integrated-podman-setup.yml
Normal file
218
configuration/playbooks/integrated-podman-setup.yml
Normal file
@@ -0,0 +1,218 @@
|
||||
---
|
||||
- name: Integrated Podman Setup - Remove Docker, Install and Configure Podman with Compose for Nomad
|
||||
hosts: all
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: 显示当前处理的节点
|
||||
debug:
|
||||
msg: "🔧 开始集成 Podman 设置: {{ inventory_hostname }}"
|
||||
|
||||
- name: 检查 Docker 服务状态
|
||||
shell: systemctl is-active docker 2>/dev/null || echo "inactive"
|
||||
register: docker_status
|
||||
changed_when: false
|
||||
|
||||
- name: 停止 Docker 服务
|
||||
systemd:
|
||||
name: docker
|
||||
state: stopped
|
||||
enabled: no
|
||||
ignore_errors: yes
|
||||
when: docker_status.stdout == "active"
|
||||
|
||||
- name: 停止 Docker socket
|
||||
systemd:
|
||||
name: docker.socket
|
||||
state: stopped
|
||||
enabled: no
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 移除 Docker 相关包
|
||||
apt:
|
||||
name:
|
||||
- docker-ce
|
||||
- docker-ce-cli
|
||||
- containerd.io
|
||||
- docker-buildx-plugin
|
||||
- docker-compose-plugin
|
||||
- docker.io
|
||||
- docker-doc
|
||||
- docker-compose
|
||||
- docker-registry
|
||||
- containerd
|
||||
- runc
|
||||
state: absent
|
||||
purge: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 清理 Docker 数据目录
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /var/lib/docker
|
||||
- /var/lib/containerd
|
||||
- /etc/docker
|
||||
- /etc/containerd
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 清理 Docker 用户组
|
||||
group:
|
||||
name: docker
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 更新包缓存
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: 安装 Podman 及相关工具
|
||||
apt:
|
||||
name:
|
||||
- podman
|
||||
- buildah
|
||||
- skopeo
|
||||
- python3-pip
|
||||
- python3-setuptools
|
||||
state: present
|
||||
retries: 3
|
||||
delay: 10
|
||||
|
||||
- name: 安装 Podman Compose via pip
|
||||
pip:
|
||||
name: podman-compose
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 启用 Podman socket 服务
|
||||
systemd:
|
||||
name: podman.socket
|
||||
enabled: yes
|
||||
state: started
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 创建 Podman 用户服务目录
|
||||
file:
|
||||
path: /etc/systemd/user
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: 验证 Podman 安装
|
||||
shell: podman --version
|
||||
register: podman_version
|
||||
|
||||
- name: 验证 Podman Compose 安装
|
||||
shell: podman-compose --version 2>/dev/null || echo "未安装"
|
||||
register: podman_compose_version
|
||||
|
||||
- name: 检查 Docker 清理状态
|
||||
shell: systemctl is-active docker 2>/dev/null || echo "已移除"
|
||||
register: final_docker_status
|
||||
|
||||
- name: 显示 Docker 移除和 Podman 安装结果
|
||||
debug:
|
||||
msg: |
|
||||
✅ 节点 {{ inventory_hostname }} Docker 移除和 Podman 安装完成
|
||||
🐳 Docker 状态: {{ final_docker_status.stdout }}
|
||||
📦 Podman 版本: {{ podman_version.stdout }}
|
||||
🔧 Compose 状态: {{ podman_compose_version.stdout }}
|
||||
|
||||
- name: 创建 Podman 系统配置目录
|
||||
file:
|
||||
path: /etc/containers
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: 配置 Podman 使用系统 socket
|
||||
copy:
|
||||
content: |
|
||||
[engine]
|
||||
# 使用系统级 socket 而不是用户级 socket
|
||||
active_service = "system"
|
||||
[engine.service_destinations]
|
||||
[engine.service_destinations.system]
|
||||
uri = "unix:///run/podman/podman.sock"
|
||||
dest: /etc/containers/containers.conf
|
||||
mode: '0644'
|
||||
|
||||
- name: 检查是否存在 nomad 用户
|
||||
getent:
|
||||
database: passwd
|
||||
key: nomad
|
||||
register: nomad_user_check
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 为 nomad 用户创建配置目录
|
||||
file:
|
||||
path: "/home/nomad/.config/containers"
|
||||
state: directory
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0755'
|
||||
when: nomad_user_check is succeeded
|
||||
|
||||
- name: 为 nomad 用户配置 Podman
|
||||
copy:
|
||||
content: |
|
||||
[engine]
|
||||
active_service = "system"
|
||||
[engine.service_destinations]
|
||||
[engine.service_destinations.system]
|
||||
uri = "unix:///run/podman/podman.sock"
|
||||
dest: /home/nomad/.config/containers/containers.conf
|
||||
owner: nomad
|
||||
group: nomad
|
||||
mode: '0644'
|
||||
when: nomad_user_check is succeeded
|
||||
|
||||
- name: 将 nomad 用户添加到 podman 组
|
||||
user:
|
||||
name: nomad
|
||||
groups: podman
|
||||
append: yes
|
||||
when: nomad_user_check is succeeded
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 创建 podman 组(如果不存在)
|
||||
group:
|
||||
name: podman
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 设置 podman socket 目录权限
|
||||
file:
|
||||
path: /run/podman
|
||||
state: directory
|
||||
mode: '0755'
|
||||
group: podman
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 验证 Podman socket 权限
|
||||
file:
|
||||
path: /run/podman/podman.sock
|
||||
mode: '0666'
|
||||
when: nomad_user_check is succeeded
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 测试 Podman 功能
|
||||
shell: podman info
|
||||
register: podman_info
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 清理 apt 缓存
|
||||
apt:
|
||||
autoclean: yes
|
||||
autoremove: yes
|
||||
|
||||
- name: 显示最终配置结果
|
||||
debug:
|
||||
msg: |
|
||||
🎉 节点 {{ inventory_hostname }} 集成 Podman 设置完成!
|
||||
📦 Podman 版本: {{ podman_version.stdout }}
|
||||
🐳 Podman Compose: {{ podman_compose_version.stdout }}
|
||||
👤 Nomad 用户: {{ 'FOUND' if nomad_user_check is succeeded else 'NOT FOUND' }}
|
||||
🔧 Podman 状态: {{ 'SUCCESS' if podman_info.rc == 0 else 'WARNING' }}
|
||||
🚀 Docker 已移除,Podman 已配置为与 Nomad 集成
|
||||
17
configuration/playbooks/manual-run-nomad-germany.yml
Normal file
17
configuration/playbooks/manual-run-nomad-germany.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
- name: Manually run Nomad agent to capture output
|
||||
hosts: germany
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run nomad agent directly
|
||||
command: /snap/bin/nomad agent -config=/etc/nomad.d/nomad.hcl
|
||||
register: nomad_agent_output
|
||||
ignore_errors: true
|
||||
|
||||
- name: Display agent output
|
||||
debug:
|
||||
msg: |
|
||||
--- Nomad Agent STDOUT ---
|
||||
{{ nomad_agent_output.stdout }}
|
||||
|
||||
--- Nomad Agent STDERR ---
|
||||
{{ nomad_agent_output.stderr }}
|
||||
12
configuration/playbooks/read-nomad-config-germany.yml
Normal file
12
configuration/playbooks/read-nomad-config-germany.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
- name: Read Nomad config on germany
|
||||
hosts: germany
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Read nomad.hcl
|
||||
command: cat /etc/nomad.d/nomad.hcl
|
||||
register: nomad_config
|
||||
ignore_errors: true
|
||||
|
||||
- name: Display config
|
||||
debug:
|
||||
msg: "{{ nomad_config.stdout }}"
|
||||
@@ -0,0 +1,126 @@
|
||||
---
|
||||
- name: 移除 Docker 并安装带 Compose 功能的 Podman
|
||||
hosts: all
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: 显示当前处理的节点
|
||||
debug:
|
||||
msg: "🔧 正在处理节点: {{ inventory_hostname }}"
|
||||
|
||||
- name: 检查 Docker 服务状态
|
||||
shell: systemctl is-active docker 2>/dev/null || echo "inactive"
|
||||
register: docker_status
|
||||
changed_when: false
|
||||
|
||||
- name: 停止 Docker 服务
|
||||
systemd:
|
||||
name: docker
|
||||
state: stopped
|
||||
enabled: no
|
||||
ignore_errors: yes
|
||||
when: docker_status.stdout == "active"
|
||||
|
||||
- name: 停止 Docker socket
|
||||
systemd:
|
||||
name: docker.socket
|
||||
state: stopped
|
||||
enabled: no
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 移除 Docker 相关包
|
||||
apt:
|
||||
name:
|
||||
- docker-ce
|
||||
- docker-ce-cli
|
||||
- containerd.io
|
||||
- docker-buildx-plugin
|
||||
- docker-compose-plugin
|
||||
- docker.io
|
||||
- docker-doc
|
||||
- docker-compose
|
||||
- docker-registry
|
||||
- containerd
|
||||
- runc
|
||||
state: absent
|
||||
purge: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 清理 Docker 数据目录
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /var/lib/docker
|
||||
- /var/lib/containerd
|
||||
- /etc/docker
|
||||
- /etc/containerd
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 清理 Docker 用户组
|
||||
group:
|
||||
name: docker
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 更新包缓存
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: 安装 Podman 及相关工具
|
||||
apt:
|
||||
name:
|
||||
- podman
|
||||
- buildah
|
||||
- skopeo
|
||||
- python3-pip
|
||||
- python3-setuptools
|
||||
state: present
|
||||
retries: 3
|
||||
delay: 10
|
||||
|
||||
- name: 安装 Podman Compose via pip
|
||||
pip:
|
||||
name: podman-compose
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 启用 Podman socket 服务
|
||||
systemd:
|
||||
name: podman.socket
|
||||
enabled: yes
|
||||
state: started
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 创建 Podman 用户服务目录
|
||||
file:
|
||||
path: /etc/systemd/user
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: 验证 Podman 安装
|
||||
shell: podman --version
|
||||
register: podman_version
|
||||
|
||||
- name: 验证 Podman Compose 安装
|
||||
shell: podman-compose --version 2>/dev/null || echo "未安装"
|
||||
register: podman_compose_version
|
||||
|
||||
- name: 检查 Docker 清理状态
|
||||
shell: systemctl is-active docker 2>/dev/null || echo "已移除"
|
||||
register: final_docker_status
|
||||
|
||||
- name: 显示节点处理结果
|
||||
debug:
|
||||
msg: |
|
||||
✅ 节点 {{ inventory_hostname }} 处理完成
|
||||
🐳 Docker 状态: {{ final_docker_status.stdout }}
|
||||
📦 Podman 版本: {{ podman_version.stdout }}
|
||||
🔧 Compose 状态: {{ podman_compose_version.stdout }}
|
||||
|
||||
- name: 清理 apt 缓存
|
||||
apt:
|
||||
autoclean: yes
|
||||
autoremove: yes
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: 安装并配置新的 Nomad Server 节点
|
||||
hosts: ash2e,ash1d,ch2
|
||||
hosts: influxdb1
|
||||
become: yes
|
||||
gather_facts: no
|
||||
|
||||
|
||||
100
configuration/playbooks/test-podman-snap-migration.yml
Normal file
100
configuration/playbooks/test-podman-snap-migration.yml
Normal file
@@ -0,0 +1,100 @@
|
||||
---
|
||||
- name: 测试将 Podman 切换到 Snap 版本 (ch2 节点)
|
||||
hosts: ch2
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: 检查当前 Podman 版本和安装方式
|
||||
shell: |
|
||||
echo "=== 当前 Podman 信息 ==="
|
||||
podman --version
|
||||
echo "安装路径: $(which podman)"
|
||||
echo "=== Snap 状态 ==="
|
||||
which snap || echo "snap 未安装"
|
||||
snap list podman 2>/dev/null || echo "Podman snap 未安装"
|
||||
echo "=== 包管理器状态 ==="
|
||||
dpkg -l | grep podman || echo "未通过 apt 安装"
|
||||
register: current_status
|
||||
|
||||
- name: 显示当前状态
|
||||
debug:
|
||||
msg: "{{ current_status.stdout }}"
|
||||
|
||||
- name: 检查 snap 是否已安装
|
||||
shell: which snap
|
||||
register: snap_check
|
||||
ignore_errors: yes
|
||||
changed_when: false
|
||||
|
||||
- name: 安装 snapd (如果未安装)
|
||||
apt:
|
||||
name: snapd
|
||||
state: present
|
||||
when: snap_check.rc != 0
|
||||
|
||||
- name: 确保 snapd 服务运行
|
||||
systemd:
|
||||
name: snapd
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: 检查当前 Podman snap 版本
|
||||
shell: snap info podman
|
||||
register: snap_podman_info
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示可用的 Podman snap 版本
|
||||
debug:
|
||||
msg: "{{ snap_podman_info.stdout if snap_podman_info.rc == 0 else '无法获取 snap podman 信息' }}"
|
||||
|
||||
- name: 停止当前 Podman 相关服务
|
||||
systemd:
|
||||
name: podman
|
||||
state: stopped
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 移除通过包管理器安装的 Podman
|
||||
apt:
|
||||
name: podman
|
||||
state: absent
|
||||
purge: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 安装 Podman snap (edge 通道)
|
||||
snap:
|
||||
name: podman
|
||||
state: present
|
||||
classic: yes
|
||||
channel: edge
|
||||
|
||||
- name: 创建符号链接 (确保 podman 命令可用)
|
||||
file:
|
||||
src: /snap/bin/podman
|
||||
dest: /usr/local/bin/podman
|
||||
state: link
|
||||
force: yes
|
||||
|
||||
- name: 验证 Snap Podman 安装
|
||||
shell: |
|
||||
/snap/bin/podman --version
|
||||
which podman
|
||||
register: snap_podman_verify
|
||||
|
||||
- name: 显示安装结果
|
||||
debug:
|
||||
msg: |
|
||||
✅ Snap Podman 安装完成
|
||||
🚀 版本: {{ snap_podman_verify.stdout_lines[0] }}
|
||||
📍 路径: {{ snap_podman_verify.stdout_lines[1] }}
|
||||
|
||||
- name: 测试 Podman 基本功能
|
||||
shell: |
|
||||
/snap/bin/podman version
|
||||
/snap/bin/podman info --format json | jq -r '.host.arch'
|
||||
register: podman_test
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示测试结果
|
||||
debug:
|
||||
msg: "Podman 测试结果: {{ podman_test.stdout if podman_test.rc == 0 else '测试失败' }}"
|
||||
77
configuration/playbooks/upgrade-podman-to-5.yml
Normal file
77
configuration/playbooks/upgrade-podman-to-5.yml
Normal file
@@ -0,0 +1,77 @@
|
||||
---
|
||||
- name: 升级 Podman 到最新版本 (warden 节点测试)
|
||||
hosts: warden
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: 检查当前 Podman 版本
|
||||
shell: podman --version
|
||||
register: current_podman_version
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示当前版本
|
||||
debug:
|
||||
msg: "当前 Podman 版本: {{ current_podman_version.stdout if current_podman_version.rc == 0 else '未安装或无法获取' }}"
|
||||
|
||||
- name: 备份现有 Podman 配置
|
||||
shell: |
|
||||
if [ -d /etc/containers ]; then
|
||||
cp -r /etc/containers /etc/containers.backup.$(date +%Y%m%d)
|
||||
fi
|
||||
if [ -d /usr/share/containers ]; then
|
||||
cp -r /usr/share/containers /usr/share/containers.backup.$(date +%Y%m%d)
|
||||
fi
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 添加 Kubic 仓库 (HTTP 跳过签名)
|
||||
shell: |
|
||||
# 添加仓库并跳过签名验证
|
||||
echo "deb [trusted=yes] http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_22.04/ /" > /etc/apt/sources.list.d/kubic-containers.list
|
||||
|
||||
- name: 更新包列表 (跳过签名验证)
|
||||
shell: apt-get update -o Acquire::AllowInsecureRepositories=true -o Acquire::AllowDowngradeToInsecureRepositories=true
|
||||
|
||||
- name: 检查仓库中可用的 Podman 版本
|
||||
shell: apt-cache policy podman
|
||||
register: podman_versions
|
||||
|
||||
- name: 显示可用的 Podman 版本
|
||||
debug:
|
||||
msg: "{{ podman_versions.stdout }}"
|
||||
|
||||
- name: 安装 Podman 5.x (强制跳过签名)
|
||||
shell: apt-get install -y --allow-unauthenticated --allow-downgrades --allow-remove-essential --allow-change-held-packages podman
|
||||
|
||||
- name: 验证 Podman 5.x 安装
|
||||
shell: |
|
||||
podman --version
|
||||
podman info --format json | jq -r '.Version.Version'
|
||||
register: podman_5_verify
|
||||
|
||||
- name: 显示升级结果
|
||||
debug:
|
||||
msg: |
|
||||
✅ Podman 升级完成
|
||||
🚀 新版本: {{ podman_5_verify.stdout_lines[0] }}
|
||||
📊 详细版本: {{ podman_5_verify.stdout_lines[1] }}
|
||||
|
||||
- name: 测试基本功能
|
||||
shell: |
|
||||
podman run --rm hello-world
|
||||
register: podman_test
|
||||
ignore_errors: yes
|
||||
|
||||
- name: 显示测试结果
|
||||
debug:
|
||||
msg: "Podman 功能测试: {{ '成功' if podman_test.rc == 0 else '失败 - ' + podman_test.stderr }}"
|
||||
|
||||
- name: 检查相关服务状态
|
||||
shell: |
|
||||
systemctl status podman.socket 2>/dev/null || echo "podman.socket 未运行"
|
||||
systemctl status containerd 2>/dev/null || echo "containerd 未运行"
|
||||
register: service_status
|
||||
|
||||
- name: 显示服务状态
|
||||
debug:
|
||||
msg: "{{ service_status.stdout }}"
|
||||
Reference in New Issue
Block a user