# -- 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