Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB

  1. ---
  2. - name: 'check if container dir exists'
  3. stat:
  4. path: '/var/lib/lxc/{{ vm_name }}'
  5. register: container_dir
  6. - name: 'check if container exists'
  7. container_exists:
  8. name: '{{ vm_name }}'
  9. register: container_exists
  10. - name: 'check if release is supported'
  11. assert:
  12. that: distro in [ 'bullseye', 'sid', 'buster' ]
  13. msg: 'release {{ distro }} not supported by debian template'
  14. - when: not (container_exists.exists and container_dir.stat.isdir)
  15. block:
  16. - name: 'create the lxc container'
  17. lxc_container:
  18. name: '{{ vm_name }}'
  19. backing_store: 'lvm'
  20. fs_size: '{{ vm_size }}'
  21. vg_name: '{{ vg_name }}'
  22. lv_name: 'vm_{{ vm_name }}'
  23. fs_type: 'xfs'
  24. container_log: true
  25. template: 'debian'
  26. template_options: '--release {{ distro }} --packages=ssh,python3'
  27. state: 'stopped'
  28. # suppress messages related to file descriptors
  29. # leaking when lvm is invoked
  30. environment:
  31. LVM_SUPPRESS_FD_WARNINGS: 1
  32. - name: 'deploy container config'
  33. template:
  34. src: 'config.j2'
  35. dest: '/var/lib/lxc/{{ vm_name }}/config'
  36. - name: 'start container'
  37. lxc_container:
  38. name: '{{ vm_name }}'
  39. state: 'started'
  40. when: auto_start|bool
  41. - name: 'update container config'
  42. template:
  43. src: 'config.j2'
  44. dest: '/var/lib/lxc/{{ vm_name }}/config'
  45. register: container_config
  46. notify: 'restart container'
  47. - name: 'set container running state'
  48. lxc_container:
  49. name: '{{ vm_name }}'
  50. state: '{{ container_state }}'
  51. register: container_running_state
  52. - name: 'update container resolv.conf'
  53. template:
  54. src: 'resolv.conf.j2'
  55. dest: '/etc/resolv.conf'
  56. delegate_to: '{{ vm_name }}'
  57. connection: 'ssh_lxc'
  58. - name: 'update container net config'
  59. copy:
  60. src: 'interfaces'
  61. dest: '/etc/network/interfaces'
  62. delegate_to: '{{ vm_name }}'
  63. connection: 'ssh_lxc'
  64. notify: 'restart container'
  65. - meta: 'flush_handlers'
  66. - name: 'add monitoring facts'
  67. set_fact:
  68. monitoring_host: '{{ monitoring_host | default([]) }} + [ "{{ vm_name }}" ]'
  69. delegate_facts: true
  70. delegate_to: 'status'