Maybe you should be using the systemctl action "reload-or-restart"?

Killing service processes out from under systemd should not be a thing.

And as Dick Visser said, we're straying from Ansible issues.

To your other question:
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.
I know of no ansible module (besides "ansible.builtin.shell") that would let you do all that in a single task. But again, unless the service is broken or the units are basically wrong, you shouldn't need to do that. The service manager should be able to handle that for you, thus, a single task should suffice.
--
Todd


On 7/12/23 7:34 AM, Stefan Hornburg (Racke) wrote:
On 12/07/2023 13:30, Dick Visser wrote:
Hii,


On Wed, 12 Jul 2023 at 12:53, Sameer Modak <[email protected]> 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="$?"


I feel we're going down a rabbit hole trying to fight ill designed systemd units with shell hacks (which include typos? ERRROR instead of ERROR). My approach would be to make sure the systemd unit is doing what it should do, and then rely on that to do its job....

Certainly!

Regards

         Racke


--
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/CAF8BbLZQ7v-K7vSnFkGsVYwm_6a9HO3f1Cf7r8yBM%2Bb_DQcj4A%40mail.gmail.com <https://groups.google.com/d/msgid/ansible-project/CAF8BbLZQ7v-K7vSnFkGsVYwm_6a9HO3f1Cf7r8yBM%2Bb_DQcj4A%40mail.gmail.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/6dc19aa9-81ee-9111-a5be-5f4b71b68047%40gmail.com.

Reply via email to