migrate_indexers.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ---
  2. # Perform actual migration of the servers
  3. #
  4. # PREREQUITES:
  5. # 1) An initial rsync should have been performed (see rsync_colddb)
  6. # 2) Cluster should be in maintenance mode
  7. #
  8. # Specify extra vars for "target", "delay", and "folders", where
  9. # folders should be an array.
  10. #
  11. # You can do this on the command-line via JSON:
  12. # ansible-playbook migrate_indexers.yml \
  13. # --extra-vars="{"target": 10.10.10.10, "delay": 30, "folders": ["folder1", "folder2"]}"
  14. #
  15. # Or put that json in a file and do:
  16. # ansible-playbook migrate_indexers.yml --extra-vars "@filename.json"
  17. #
  18. - hosts: "{{ target }}"
  19. become: true
  20. become_user: splunk
  21. serial: 1
  22. tasks:
  23. # Verify variables
  24. - name: Variable check - folders
  25. fail: msg="Variable 'folders' is not defined or is invalid. Please see playbook for how to configure extra-vars."
  26. when: (folders is not defined)
  27. - name: Variable check - delay
  28. fail: msg="Variable 'delay' is not defined or is invalid. Please see playbook for how to configure extra-vars."
  29. when: (delay is not defined)
  30. # Verify folder exists
  31. - name: Ensure folder already exists
  32. stat:
  33. path: /opt/splunk/var/lib/splunkcold/{{ item }}/colddb
  34. register: colddbpath
  35. with_items: "{{ folders }}"
  36. - name: Fail if the folder doesn't exist
  37. fail: msg="One of the colddb folders does not exist."
  38. when: not(item.stat.isdir is defined and item.stat.isdir)
  39. with_items: "{{ colddbpath.results }}"
  40. - debug:
  41. msg: "Cold Paths exist. Good."
  42. when: item.stat.isdir is defined and item.stat.isdir
  43. with_items: "{{ colddbpath.results }}"
  44. # Verify migrated folder does not exist (DO NOT RUN TWICE!)
  45. - name: Ensure migrated folder does not exist
  46. stat:
  47. path: /opt/splunk/var/lib/splunk/{{ item }}/colddb.migrated
  48. register: colddbmigratedpath
  49. with_items: "{{ folders }}"
  50. - name: Fail if the migrated folder exist
  51. fail: msg="One of the migrated folders already exists. (Already run on this index?)"
  52. when: item.stat.isdir is defined and item.stat.isdir
  53. with_items: "{{ colddbmigratedpath.results }}"
  54. - debug:
  55. msg: "Migrated Cold Paths do not exist. Good."
  56. when: not(item.stat.isdir is defined and item.stat.isdir)
  57. with_items: "{{ colddbmigratedpath.results }}"
  58. # Stop Splunk
  59. - name: Stop Splunk
  60. command: /opt/splunk/bin/splunk stop
  61. - name: rsync cold data
  62. command: rsync -avz --delete /opt/splunk/var/lib/splunk/{{ item }}/colddb/ /opt/splunk/var/lib/splunkcold/{{ item }}/colddb/
  63. # Run this asynchyronously for one hour, polling every 30.
  64. # async: 604800
  65. # poll: 60
  66. register: rsync_result
  67. with_items: "{{ folders }}"
  68. - name: overwrite indexes.conf
  69. copy:
  70. src: ../files/indexes.conf
  71. dest: /opt/splunk/etc/slave-apps/_cluster/local/indexes.conf
  72. owner: splunk
  73. group: splunk
  74. mode: 0600
  75. - name: Rename Colddb path
  76. command: mv /opt/splunk/var/lib/splunk/{{ item }}/colddb /opt/splunk/var/lib/splunk/{{ item }}/colddb.migrated
  77. with_items: "{{ folders }}"
  78. - name: Btool Check for Good Measure
  79. command: /opt/splunk/bin/splunk btool check
  80. - name: start splunk
  81. command: /opt/splunk/bin/splunk start
  82. - name: sleep after
  83. command: sleep {{delay}}