ops-docker-loopback-to-direct-lvm.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/ansible-playbook
  2. ---
  3. # This playbook coverts docker to go from loopback to direct-lvm (the Red Hat recommended way to run docker).
  4. #
  5. # It requires the block device to be already provisioned and attached to the host. This is a generic playbook,
  6. # meant to be used for manual conversion. For AWS specific conversions, use the other playbook in this directory.
  7. #
  8. # To run:
  9. # ./ops-docker-loopback-to-direct-lvm.yml -e cli_host=<host to run on> -e cli_docker_device=<path to device>
  10. #
  11. # Example:
  12. # ./ops-docker-loopback-to-direct-lvm.yml -e cli_host=twiesttest-master-fd32 -e cli_docker_device=/dev/sdb
  13. #
  14. # Notes:
  15. # * This will remove /var/lib/docker!
  16. # * You may need to re-deploy docker images after this is run (like monitoring)
  17. - name: Fix docker to have a provisioned iops drive
  18. hosts: "{{ cli_host }}"
  19. user: root
  20. connection: ssh
  21. gather_facts: no
  22. pre_tasks:
  23. - fail:
  24. msg: "This playbook requires {{item}} to be set."
  25. when: "{{ item }} is not defined or {{ item }} == ''"
  26. with_items:
  27. - cli_docker_device
  28. - name: start docker
  29. service:
  30. name: docker
  31. state: started
  32. - name: Determine if loopback
  33. shell: docker info | grep 'Data file:.*loop'
  34. register: loop_device_check
  35. ignore_errors: yes
  36. - debug:
  37. var: loop_device_check
  38. - name: fail if we don't detect loopback
  39. fail:
  40. msg: loopback not detected! Please investigate manually.
  41. when: loop_device_check.rc == 1
  42. - name: stop zagg client monitoring container
  43. service:
  44. name: oso-rhel7-zagg-client
  45. state: stopped
  46. ignore_errors: yes
  47. - name: stop pcp client monitoring container
  48. service:
  49. name: oso-f22-host-monitoring
  50. state: stopped
  51. ignore_errors: yes
  52. - name: "check to see if {{ cli_docker_device }} exists"
  53. command: "test -e {{ cli_docker_device }}"
  54. register: docker_dev_check
  55. ignore_errors: yes
  56. - debug: var=docker_dev_check
  57. - name: "fail if {{ cli_docker_device }} doesn't exist"
  58. fail:
  59. msg: "{{ cli_docker_device }} doesn't exist. Please investigate"
  60. when: docker_dev_check.rc != 0
  61. - name: stop docker
  62. service:
  63. name: docker
  64. state: stopped
  65. - name: delete /var/lib/docker
  66. command: rm -rf /var/lib/docker
  67. - name: remove /var/lib/docker
  68. command: rm -rf /var/lib/docker
  69. - name: copy the docker-storage-setup config file
  70. copy:
  71. content: >
  72. DEVS={{ cli_docker_device }}
  73. VG=docker_vg
  74. dest: /etc/sysconfig/docker-storage-setup
  75. owner: root
  76. group: root
  77. mode: 0664
  78. - name: docker storage setup
  79. command: docker-storage-setup
  80. register: setup_output
  81. - debug: var=setup_output
  82. - name: extend the vg
  83. command: lvextend -l 90%VG /dev/docker_vg/docker-pool
  84. register: extend_output
  85. - debug: var=extend_output
  86. - name: start docker
  87. service:
  88. name: docker
  89. state: restarted
  90. - name: docker info
  91. command: docker info
  92. register: dockerinfo
  93. - debug: var=dockerinfo