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.

58 lines
1.5 KiB

7 years ago
7 years ago
  1. ---
  2. - hosts: localhost
  3. tasks:
  4. - fail:
  5. msg: "please define a vm name with --extra-vars vm=vm_name"
  6. when: vm is undefined
  7. failed_when: True
  8. - hosts: vm_hosts
  9. tasks:
  10. - name: check for lxc container existance
  11. container_exists:
  12. name: "{{ vm }}"
  13. register: container_exists
  14. failed_when: false
  15. - debug:
  16. msg: "{{ ansible_hostname }} cointains a vm named {{ vm }}"
  17. when: '"exists" in container_exists and container_exists.exists'
  18. - hosts: '{{ lxc_host }}'
  19. vars_prompt:
  20. - name: lxc_host
  21. prompt: 'what lxc host?'
  22. private: no
  23. - name: confirm1
  24. prompt: 'are you sure you want to delete the container (NO/yes)?'
  25. private: no
  26. - name: confirm2
  27. prompt: 'if you really are sure, enter the container name again'
  28. private: no
  29. tasks:
  30. - name: check for lxc container existance
  31. container_exists:
  32. name: "{{ vm }}"
  33. register: container_exists
  34. when: container_exists
  35. - fail:
  36. msg: "Task aborted by the user."
  37. when: "confirm1 != 'yes' or confirm2 != '{{ vm }}'"
  38. - block:
  39. - name: shutdown lxc container
  40. lxc_container:
  41. name: "{{ vm }}"
  42. state: stopped
  43. - name: clean LVM volume
  44. command: "dd if=/dev/zero of=/dev/{{ inventory_hostname }}vg/vm_{{ vm }} bs=1M count=128"
  45. - name: delete lxc container
  46. lxc_container:
  47. name: "{{ vm }}"
  48. state: absent
  49. when: "confirm1 == 'yes' and confirm2 == '{{ vm }}'"