I get it . But this is specific case where my current process is not
managed by systemd so i had to use pkill anyways.
Now issue is shell module with if else is not working for me correctly.
Like its giving rc -9. if i copy same shell script and rung using shell
module like bash /tmp/zkproc.sh it works.
Reason to post here is due to shell module multiple command not working as
expected. Below is shell script. Now i had to use grep -v "ERROR;et="$?"
because sometime process does says its running but log has some errors
which cant be ignored.
if pkill --signal 9 -f zookeeper.properties ; then
sleep 2;systemctl start confluent-zookeeper510; sleep 2; echo "stat"
| nc localhost 2181;st="$?"
systemctl status confluent-zookeeper5910 -l | grep -v ERROR;et="$?"
[[ $st -eq 0 && $et -eq 0 ]] && exit 0 || exit 1
else
exit 1
fi
On Wednesday, July 12, 2023 at 5:01:27 PM UTC+5: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....
>
>
>
--
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/92ca19b8-9cc7-463d-a2fb-05aa9572ce0an%40googlegroups.com.