commit 070bee0a7608b57c350c8a9a9c2f64c459e2eb5c Author: carry Date: Sun Jul 12 20:30:30 2026 +0800 添加 Ansible 配置文件和多个主机清单文件 diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..4a75f0f --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +remote_tmp = /tmp/.ansible-${USER} diff --git a/apt-upgrade.yml b/apt-upgrade.yml new file mode 100644 index 0000000..7d92823 --- /dev/null +++ b/apt-upgrade.yml @@ -0,0 +1,16 @@ +--- +- hosts: all + gather_facts: no + become: yes + + tasks: + - name: apt update + ansible.builtin.apt: + update_cache: yes + cache_valid_time: 0 + + - name: apt full-upgrade + ansible.builtin.apt: + upgrade: full + autoremove: yes + autoclean: yes diff --git a/debian_servers.ini b/debian_servers.ini new file mode 100644 index 0000000..433d10f --- /dev/null +++ b/debian_servers.ini @@ -0,0 +1,12 @@ +[cloud_servers] +hkyc1 ansible_host=hkyc1.tl.lan.carry.fit ansible_user=root ansible_ssh_pass="{{ ssh_password3 }}" +baota-home ansible_host=192.168.5.127 ansible_user=root ansible_ssh_pass="{{ ssh_password2 }}" +1panel-home ansible_host=192.168.5.238 ansible_user=root ansible_ssh_pass="{{ ssh_password2 }}" +baota-tower ansible_host=192.168.15.238 ansible_user=root ansible_ssh_pass="{{ ssh_password2 }}" +1panel-tower ansible_host=192.168.15.246 ansible_user=root ansible_ssh_pass="{{ ssh_password2 }}" + +[cloud_servers:vars] +ansible_connection=ssh +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +ansible_python_interpreter=auto_silent +ansible_ssh_private_key_file=~/.ssh/id_ed25519 \ No newline at end of file diff --git a/fix-auto-bind.yml b/fix-auto-bind.yml new file mode 100644 index 0000000..771141a --- /dev/null +++ b/fix-auto-bind.yml @@ -0,0 +1,105 @@ +--- +- hosts: fnos + gather_facts: no + become: yes + vars: + src_bases: + fn-home: "/vol00/HGST HSH721414ALE6M4" + fn-tower: "/vol00/HSH721414ALN6M0" + tasks: + - name: Deploy fixed auto-bind script + ansible.builtin.copy: + dest: /usr/local/bin/auto-bind-same-dirs.sh + mode: "0755" + content: | + #!/bin/bash + set -euo pipefail + + SRC_BASE="{{ src_bases[inventory_hostname] }}" + DST_BASE="/vol1/1000" + LOG_TAG="auto-bind-same-dirs" + + logger -t "$LOG_TAG" "start" + + if [ ! -d "$SRC_BASE" ]; then + logger -t "$LOG_TAG" "source base not found: $SRC_BASE" + exit 0 + fi + + if [ ! -d "$DST_BASE" ]; then + logger -t "$LOG_TAG" "target base not found: $DST_BASE" + exit 0 + fi + + find "$DST_BASE" -mindepth 1 -maxdepth 1 -type d | while read -r dst_dir; do + name="$(basename "$dst_dir")" + src_dir="$SRC_BASE/$name" + + if [ -d "$src_dir" ]; then + if mountpoint -q "$dst_dir" && stat "$dst_dir/." >/dev/null 2>&1; then + logger -t "$LOG_TAG" "skip already mounted: $dst_dir" + else + umount "$dst_dir" 2>/dev/null || true + mount --bind "$src_dir" "$dst_dir" + logger -t "$LOG_TAG" "mounted $src_dir -> $dst_dir" + fi + fi + done + + logger -t "$LOG_TAG" "done" + exit 0 + + - name: Deploy service unit + ansible.builtin.copy: + dest: /etc/systemd/system/auto-bind-same-dirs.service + mode: "0644" + content: | + [Unit] + Description=Bind mount NAS directories + + [Service] + Type=oneshot + ExecStart=/usr/local/bin/auto-bind-same-dirs.sh + + - name: Deploy timer unit + ansible.builtin.copy: + dest: /etc/systemd/system/auto-bind-same-dirs.timer + mode: "0644" + content: | + [Unit] + Description=Periodic bind mount check for external disks + + [Timer] + OnBootSec=15s + OnUnitActiveSec=60s + + [Install] + WantedBy=timers.target + + - name: Stop and disable old path unit + ansible.builtin.systemd: + name: auto-bind-same-dirs.path + state: stopped + enabled: false + failed_when: false + + - name: Remove old path unit file + ansible.builtin.file: + path: /etc/systemd/system/auto-bind-same-dirs.path + state: absent + + - name: systemd daemon-reload + ansible.builtin.systemd: + daemon_reload: true + + - name: Reset any failed state on auto-bind units + ansible.builtin.command: + cmd: systemctl reset-failed auto-bind-same-dirs.service auto-bind-same-dirs.timer + failed_when: false + changed_when: false + + - name: Enable and start timer + ansible.builtin.systemd: + name: auto-bind-same-dirs.timer + enabled: true + state: started diff --git a/fnos.ini b/fnos.ini new file mode 100644 index 0000000..91a92fd --- /dev/null +++ b/fnos.ini @@ -0,0 +1,9 @@ +[fnos] +fn-home ansible_host=fn.home.lan.carry.fit ansible_user=carry ansible_ssh_pass="{{ ssh_password1 }}" +fn-tower ansible_host=fn.tower.lan.carry.fit ansible_user=carry ansible_ssh_pass="{{ ssh_password1 }}" + +[fnos:vars] +ansible_connection=ssh +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +ansible_python_interpreter=auto_silent +ansible_ssh_private_key_file=~/.ssh/id_ed25519 diff --git a/group_vars/all/secret.yml b/group_vars/all/secret.yml new file mode 100644 index 0000000..64c93de --- /dev/null +++ b/group_vars/all/secret.yml @@ -0,0 +1,5 @@ +ansible_become_pass: "{{ ansible_ssh_pass }}" + +ssh_password1: Lkr*772769282 +ssh_password2: 87282458 +ssh_password3: '79S' diff --git a/openwrt.ini b/openwrt.ini new file mode 100644 index 0000000..fac38ef --- /dev/null +++ b/openwrt.ini @@ -0,0 +1,9 @@ +[openwrt] +openwrt-home ansible_host=openwrt.home.lan.carry.fit ansible_user=root ansible_ssh_pass="{{ ssh_password2 }}" +openwrt-tower ansible_host=openwrt.tower.lan.carry.fit ansible_user=root ansible_ssh_pass="{{ ssh_password1 }}" + +[openwrt:vars] +ansible_connection=ssh +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +ansible_python_interpreter=auto_silent +ansible_ssh_private_key_file=~/.ssh/id_ed25519 \ No newline at end of file diff --git a/pve.ini b/pve.ini new file mode 100644 index 0000000..ef8dfd0 --- /dev/null +++ b/pve.ini @@ -0,0 +1,9 @@ +[proxmox] +pvehome ansible_host=pve.home.lan.carry.fit ansible_user=root ansible_ssh_pass="{{ ssh_password1 }}" +pvetower ansible_host=pve.tower.lan.carry.fit ansible_user=root ansible_ssh_pass="{{ ssh_password1 }}" + +[proxmox:vars] +ansible_connection=ssh +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +ansible_python_interpreter=auto_silent +ansible_ssh_private_key_file=~/.ssh/id_ed25519 \ No newline at end of file