添加 Ansible 配置文件和多个主机清单文件
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
[defaults]
|
||||||
|
remote_tmp = /tmp/.ansible-${USER}
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
ansible_become_pass: "{{ ansible_ssh_pass }}"
|
||||||
|
|
||||||
|
ssh_password1: Lkr*772769282
|
||||||
|
ssh_password2: 87282458
|
||||||
|
ssh_password3: '<QyY$y#ZeF}>79S'
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user