migrate_single_indexer.yml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ---
  2. # Perform actual migration of a server.
  3. # PREREQUITES:
  4. # 1) An initial rsync should have been performed (see rsync_colddb)
  5. # 2) Cluster should be in maintenance mode
  6. # 3) This should be called on a single target, though the serial
  7. # limit probably makes it safe.
  8. # 4) DO NOT RUN TWICE (though it should prevent that)
  9. #
  10. # Specify extra vars for both "target" and "folder"
  11. #
  12. # e.g.:
  13. # ansible-playbook migrate_single_indexer.yml --extra-vars="target=10.10.10.10 folder=defaultdb"
  14. - hosts: "{{ target }}"
  15. become: true
  16. become_user: splunk
  17. serial: 1
  18. tasks:
  19. # Verify folder is defined
  20. - name: Variable check
  21. fail: msg="Variable 'folder' is not defined or is invalid. Please run with --extra-vars=\"target=x folder=dbfolder\""
  22. when: (folder is not defined)
  23. # Verify folder exists
  24. - name: Ensure folder already exists
  25. stat:
  26. path: /opt/splunk/var/lib/splunkcold/{{ folder }}/colddb
  27. register: colddbpath
  28. - name: Fail if the folder doesn't exist
  29. fail: msg="The colddb folder does not exist."
  30. when: not(colddbpath.stat.isdir is defined and colddbpath.stat.isdir)
  31. - debug:
  32. msg: "Cold Path exists. Good."
  33. when: colddbpath.stat.isdir is defined and colddbpath.stat.isdir
  34. # Verify migrated folder does not exist (DO NOT RUN TWICE!)
  35. - name: Ensure migrated folder does not exist
  36. stat:
  37. path: /opt/splunk/var/lib/splunk/{{ folder }}/colddb.migrated
  38. register: colddbmigratedpath
  39. - name: Fail if the migrated folder exist
  40. fail: msg="The migrated folder already exists. (Already run on this index?)"
  41. when: colddbmigratedpath.stat.isdir is defined and colddbmigratedpath.stat.isdir
  42. - debug:
  43. msg: "Migrated Cold Path does not exist. Good."
  44. when: not(colddbmigratedpath.stat.isdir is defined and coldmigratedpath.stat.isdir)
  45. # Stop Splunk
  46. - name: Stop Splunk
  47. command: /opt/splunk/bin/splunk stop
  48. - name: rsync cold data
  49. command: rsync -avz --delete /opt/splunk/var/lib/splunk/{{ folder }}/colddb/ /opt/splunk/var/lib/splunkcold/{{ folder }}/colddb/
  50. # Run this asynchyronously for one hour, polling every 30.
  51. # async: 604800
  52. # poll: 60
  53. register: rsync_result
  54. - name: overwrite indexes.conf
  55. copy:
  56. src: ../files/indexes.conf
  57. dest: /opt/splunk/etc/slave-apps/_cluster/local/indexes.conf
  58. owner: splunk
  59. group: splunk
  60. mode: 0600
  61. - name: Rename Colddb path
  62. command: mv /opt/splunk/var/lib/splunk/{{ folder }}/colddb /opt/splunk/var/lib/splunk/{{ folder }}/colddb.migrated
  63. - name: Btool Check for Good Measure
  64. command: /opt/splunk/bin/splunk btool check
  65. - name: start splunk
  66. command: /opt/splunk/bin/splunk start