Created
July 14, 2022 15:33
-
-
Save sionsmith/8decb35ea3615f4d8366b2f9ab092017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- This ansible playbook is for rolling restart of kafka service | |
# | |
# -- Here MyEnv is the variable which we need to define while running the ansible command | |
# | |
# -- For e.g. if we want to restart kafka service in PROD run below command. | |
# $ ansible-playbook -kK --sudo -e MyEnv="prod" rolling_restart_kafka.yml | |
# | |
# -- In above command, make sure that ansible inventory file(default is /etc/ansible/hosts) has the appropriate hosts grouped together in "prod" | |
# | |
# -- If default /etc/ansible/hosts doesn't have desired grouping, create an inventory file "mylocalinventory" locally with desired hostnames | |
# $ ansible-playbook -i mylocalinventory -kK --sudo -e MyEnv="prod" rolling_restart_kafka.yml | |
- hosts: "{{ MyEnv }}" | |
serial: 1 | |
tasks: | |
- name: Restarting Kafka on {{ansible_hostname}} | |
service: | |
name: kafka | |
state: restarted | |
- name: Wait for restart to complete on host {{ansible_hostname}} and listen on port 9092 | |
wait_for: | |
host: "{{ansible_default_ipv4.address}}" | |
port: 9092 | |
- name: Wait for 60 seconds to complete the restart of kafka on {{ansible_hostname}} | |
wait_for: | |
timeout: 60 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment