install-lxcfs.yml 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. - name: Install lxcfs
  2. package:
  3. name: lxcfs
  4. state: present
  5. become: true
  6. - name: Enable and start lxcfs service
  7. systemd:
  8. name: lxcfs
  9. state: started
  10. enabled: true
  11. become: true
  12. # 不同发行版 lxcfs 挂载点可能为 /var/lib/lxc/lxcfs、/var/lib/lxcfs 等,启动后从 /proc/mounts 与常见目录探测
  13. - name: Detect lxcfs mount path on target host
  14. ansible.builtin.shell: |
  15. set -eu
  16. p="$(awk '$3=="fuse.lxcfs" {print $2; exit}' /proc/mounts 2>/dev/null || true)"
  17. if [ -n "${p:-}" ]; then printf '%s' "$p"; exit 0; fi
  18. p="$(awk '/lxcfs/ && /fuse/ {print $2; exit}' /proc/mounts 2>/dev/null || true)"
  19. if [ -n "${p:-}" ]; then printf '%s' "$p"; exit 0; fi
  20. for d in /var/lib/lxc/lxcfs /var/lib/lxcfs; do
  21. if [ -d "$d" ] && { [ -e "$d/proc/uptime" ] || [ -d "$d/proc" ]; }; then
  22. printf '%s' "$d"
  23. exit 0
  24. fi
  25. done
  26. for d in /var/lib/lxc/lxcfs /var/lib/lxcfs; do
  27. if [ -d "$d" ]; then printf '%s' "$d"; exit 0; fi
  28. done
  29. exit 1
  30. args:
  31. executable: /bin/bash
  32. register: lxcfs_path_detect
  33. changed_when: false
  34. become: true
  35. retries: 8
  36. delay: 2
  37. until: lxcfs_path_detect.rc == 0 and (lxcfs_path_detect.stdout | default('') | trim | length > 0)
  38. - name: Set lxcfs_path in host.conf from detected path
  39. ansible.builtin.lineinfile:
  40. path: /etc/yunion/host.conf
  41. regexp: '^lxcfs_path:'
  42. line: "lxcfs_path: {{ lxcfs_path_detect.stdout | trim }}"
  43. state: present
  44. create: true
  45. mode: '0644'
  46. become: true