Infact I tried code pasted by still gives same error.
- name: Kill running java processes and start newly configured systemd
throttle: 1
# ignore_errors: yes
any_errors_fatal: true
shell: |
if pkill --signal 9 -f zookeeper.properties ; then
sleep 6
systemctl start confluent-zookeeper510
fi
systemctl status confluent-zookeeper510
register: zkstart
failed_when: zkstart.rc != 0
when: not zkmode.stdout_lines is search('leader')
On Wednesday, July 12, 2023 at 4:23:06 PM UTC+5:30 Sameer Modak wrote:
> Hi Todd,
>
> I tried to run script with shell module but it fails with below error,
>
> [kafka-3: FAILED! => {"changed": true, "cmd": "if pkill --signal 9 -f
> zookeeper.properties ; then\nsystemctl start
> confluent-zookeeper510\nelse\nexit 1\nfi\nsystemctl status
> confluent-zookeeper510\n", "delta": "0:00:00.034111", "end": "2023-07-12
> 10:31:58.344951", "failed_when_result": true, "msg": "non-zero return
> code", "rc": -9, "start": "2023-07-12 10:31:58.310840", "stderr": "",
> "stderr_lines": [], "stdout": "", "stdout_lines": []}
>
> fatal: [kafka-4]: FAILED! => {"changed": true, "cmd": "if pkill --signal 9
> -f zookeeper.properties ; then\nsystemctl start
> confluent-zookeeper510\nelse\nexit 1\nfi\nsystemctl status
> confluent-zookeeper510\n", "delta": "0:00:00.032830", "end": "2023-07-12
> 10:31:59.744091", "failed_when_result": true, "msg": "non-zero return
> code", "rc": -9, "start": "2023-07-12 10:31:59.711261", "stderr": "",
> "stderr_lines": [], "stdout": "", "stdout_lines": []}
>
> ===========================================================================
>
> code:
>
> - name: Kill running java processes and start newly configured systemd
>
> throttle: 1
>
> # ignore_errors: yes
>
> any_errors_fatal: true
>
> shell: |
>
> if [ pkill --signal 9 -f zookeeper.properties ] ; then
>
> systemctl start confluent-zookeeper510; sleep 2; echo "stat" | nc
> localhost 2181;st="$?" systemctl status confluent-zookeeper510 -l | grep -v
> ERRROR;et="$?"
>
> [[ $st -eq 0 && $et -eq 0 ]] && exit 0 || exit 1
>
> else
>
> exit 1
>
> fi
>
> register: zkstart
>
> failed_when: zkstart.rc != 0
>
> when: not zkmode.stdout_lines is search('leader')
>
> On Wednesday, July 12, 2023 at 1:29:58 PM UTC+5:30 Sameer Modak wrote:
>
>> First of all Thanks a lot for introducing me pkill way otherwise i would
>> have written one more task to register the process id.
>>
>> Many thanks Todd.
>>
>> Secondly, as its impossible to explore entire tool like ansible hence
>> just asking you the question, Does it even possible to do above things
>> using ansible module in single task???
>> like find process id of process and kill if it doesnt exist do not
>> proceed with other hosts as well.
>>
>>
>>
>> On Tuesday, July 11, 2023 at 9:59:59 PM UTC+5:30 Todd Lewis wrote:
>>
>>> Regrettably, pgrep and pkill seem widely unknown.
>>>
>>> - name: Kill zookeeper processes and restart service
>>> ansible.builtin.shell: |
>>> if pkill --signal 9 -f zookeeper.properties ; then
>>> sleep 6
>>> systemctl start confluent-zookeeper510
>>> fi
>>> systemctl status confluent-zookeeper510
>>> register: zkstart
>>>
>>>
>>> On 7/11/23 10:26 AM, Sameer Modak wrote:
>>>
>>> I have used shell module and failed when combination to achieve this.
>>>
>>> - name: Get running processes list from remote host
>>>
>>> shell: "ps -efw | grep -e zookeeper.properties | grep -v grep |awk
>>> '{print $2}'"
>>>
>>> register: runningzkprc
>>>
>>> - name: Kill running processes
>>>
>>> throttle: 1
>>>
>>> # ignore_errors: yes
>>>
>>> shell: |
>>>
>>> kill -9 "{{ runningzkprc.stdout_lines[0] }}"
>>>
>>> sleep 3
>>>
>>> sleep 3
>>>
>>> systemctl start confluent-zookeeper510
>>>
>>> systemctl status confluent-zookeeper510 -l| grep -i error
>>>
>>> register: zkstart
>>>
>>> failed_when: zkstart.rc != 0
>>>
>>> when: not zkmode.stdout_lines is search('leader')
>>>
>>> On Tuesday, July 11, 2023 at 12:47:04 AM UTC+5:30 Sameer Modak wrote:
>>>
>>>> Hello team,
>>>>
>>>> I am trying to restart zookeeper service on all 3 nodes sequentially ,
>>>> we want restart zookeeper service one by one but it will be only run on
>>>> 2nd
>>>> server if 1st server zookeeper service was successful. How do i achieve
>>>> this in 1 task .
>>>>
>>>> task should fail if service is not properly restarted.
>>>>
>>>> - name: restart zookeeper one by one on follower first and ensure all
>>>> is good
>>>>
>>>> throttle: 1
>>>>
>>>> service:
>>>>
>>>> name: 'confluent-zookeeper'
>>>>
>>>> state: restarted
>>>>
>>>> when: not zkmode.stdout_lines is search('leader')
>>>>
>>>>
>>>> - name: check follower zookeeper are up and running
>>>>
>>>> shell: 'systemctl status confluent-zookeeper -l| grep -i error ||
>>>> systemctl status confluent-zookeeper | grep failed'
>>>>
>>>> register: zkstatus
>>>>
>>>> failed_when: zkstatus.rc == 0
>>>>
>>>>
>>>> Now in this case , 1 task is getting executed on all hosts despite
>>>> having error in logs . I want it to be failed as soon as it has error and
>>>> should not continue on next server.
>>>>
>>>>
>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/7b8e12de-8c99-4f85-ba9a-618f7308cdc9n%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/ansible-project/7b8e12de-8c99-4f85-ba9a-618f7308cdc9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>>
>>> --
>>> Todd
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/6d47e620-c072-47d7-b694-967c4f837ceen%40googlegroups.com.