--- # Perform actual migration of the servers # # PREREQUITES: # 1) An initial rsync should have been performed (see rsync_colddb) # 2) Cluster should be in maintenance mode # # Specify extra vars for "target", "delay", and "folders", where # folders should be an array. # # You can do this on the command-line via JSON: # ansible-playbook migrate_indexers.yml \ # --extra-vars="{"target": 10.10.10.10, "delay": 30, "folders": ["folder1", "folder2"]}" # # Or put that json in a file and do: # ansible-playbook migrate_indexers.yml --extra-vars "@filename.json" # - hosts: "{{ target }}" become: true become_user: splunk serial: 1 tasks: # Verify variables - name: Variable check - folders fail: msg="Variable 'folders' is not defined or is invalid. Please see playbook for how to configure extra-vars." when: (folders is not defined) - name: Variable check - delay fail: msg="Variable 'delay' is not defined or is invalid. Please see playbook for how to configure extra-vars." when: (delay is not defined) # Verify folder exists - name: Ensure folder already exists stat: path: /opt/splunk/var/lib/splunkcold/{{ item }}/colddb register: colddbpath with_items: "{{ folders }}" - name: Fail if the folder doesn't exist fail: msg="One of the colddb folders does not exist." when: not(item.stat.isdir is defined and item.stat.isdir) with_items: "{{ colddbpath.results }}" - debug: msg: "Cold Paths exist. Good." when: item.stat.isdir is defined and item.stat.isdir with_items: "{{ colddbpath.results }}" # Verify migrated folder does not exist (DO NOT RUN TWICE!) - name: Ensure migrated folder does not exist stat: path: /opt/splunk/var/lib/splunk/{{ item }}/colddb.migrated register: colddbmigratedpath with_items: "{{ folders }}" - name: Fail if the migrated folder exist fail: msg="One of the migrated folders already exists. (Already run on this index?)" when: item.stat.isdir is defined and item.stat.isdir with_items: "{{ colddbmigratedpath.results }}" - debug: msg: "Migrated Cold Paths do not exist. Good." when: not(item.stat.isdir is defined and item.stat.isdir) with_items: "{{ colddbmigratedpath.results }}" # Stop Splunk - name: Stop Splunk command: /opt/splunk/bin/splunk stop - name: rsync cold data command: rsync -avz --delete /opt/splunk/var/lib/splunk/{{ item }}/colddb/ /opt/splunk/var/lib/splunkcold/{{ item }}/colddb/ # Run this asynchyronously for one hour, polling every 30. # async: 604800 # poll: 60 register: rsync_result with_items: "{{ folders }}" - name: overwrite indexes.conf copy: src: ../files/indexes.conf dest: /opt/splunk/etc/slave-apps/_cluster/local/indexes.conf owner: splunk group: splunk mode: 0600 - name: Rename Colddb path command: mv /opt/splunk/var/lib/splunk/{{ item }}/colddb /opt/splunk/var/lib/splunk/{{ item }}/colddb.migrated with_items: "{{ folders }}" - name: Btool Check for Good Measure command: /opt/splunk/bin/splunk btool check - name: start splunk command: /opt/splunk/bin/splunk start - name: sleep after command: sleep {{delay}}