Shell Module Code Not Executing

31 views
Skip to first unread message

Jitender J

unread,
Dec 23, 2021, 3:27:18 AM12/23/21
to Ansible Project
Hi Team,

Need you help on below issue 

I am facing issue where code inside shell module is not getting executed over some remote server, ansible just passing the got without executing without any error, 

Dick Visser

unread,
Dec 23, 2021, 3:30:32 AM12/23/21
to ansible...@googlegroups.com
That's almost zero information. 
Provide a full playbook and any other relevant information. 


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/40b39be1-57a3-4842-86c4-cdc638a87845n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Jitender J

unread,
Dec 23, 2021, 3:45:00 AM12/23/21
to ansible...@googlegroups.com
Hi 

Below is the piece of code I am trying to execute, it is running fine over 500 nodes but there are some hosts in different environments where ansible not executing the code inside the shell module
just passing the code without any error/output 
#################################################################
 hosts: smca
 # tags: Node_check
  gather_facts: no
  user: ops
  tasks:

    - name: Executing Cluster Node Count Check On CA
      shell: |
        node_pipe_sepertated=`echo "{{ Nodes }}"|tr ',' '|'`
        c_id1=`for i in "$node_pipe_sepertated" ;do /sc/bin/smconfd smsm |egrep $i|awk '{print $(NF-5 )}';done`
        c_id=`echo "$c_id1"|tr -s ' ' '\n'|sort -u|tr -s '\n' ' '`
        echo "c id is $c_id"
         for i in ${c_id[@]};
         do
           echo "$i"
           Count=`/sc/bin/smconfd smsm |awk -v a=$i '$10 == a {print $NF}'|awk -F'.logs' '{print $1}'|wc -l`
           instances=`/sc/bin/smconfd smsm |awk -v a=$i '$10 == a {print $NF}'|awk -F'.logs' '{print $1}'`
           echo -e "\e[34m##### Nodes In Cluster #####\e[0m"

           if [ "$Count" -lt 2 ];then
              echo -e "\e[1;31mCRITICAL: Number Of Nodes in Cluster $Count \e[0m"
              echo "$instances"
              exit 2
           else
             echo -e "\e[1;32mOk: Number Of Nodes in Cluster $Count \e[0m"
             echo "$instances"

           fi
           echo " "
         done
      args:
       executable: /bin/bash
      ignore_errors: true
      when: smca_role==  true
###########################################




--
Regards,
Jitender

Stefan Hornburg (Racke)

unread,
Dec 23, 2021, 3:49:58 AM12/23/21
to ansible...@googlegroups.com
On 23/12/2021 09:44, 'Jitender J' via Ansible Project wrote:
> Hi
>
> Below is the piece of code I am trying to execute, it is running fine over 500 nodes but there are some hosts in different environments where ansible not executing the code inside the shell module

Problems with arbitrary shell scripts is not related to Ansible IMHO.

Regards
Racke
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/40b39be1-57a3-4842-86c4-cdc638a87845n%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/40b39be1-57a3-4842-86c4-cdc638a87845n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> Sent from a mobile device - please excuse the brevity, spelling and punctuation.
>
> --
> 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 ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwOGo1jjaWeMJ4%3DCeB0p7U3cY0%3DF4OsDgudTeTt7VMoTYA%40mail.gmail.com <https://groups.google.com/d/msgid/ansible-project/CAL8fbwOGo1jjaWeMJ4%3DCeB0p7U3cY0%3DF4OsDgudTeTt7VMoTYA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
>
>
> --
> *Regards,
> *
> *Jitender*
>
> --
> 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 ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAMO4JZvLGMqY29JtWBSgkGi9_8ZVijv6HwXWjevm%2BQCWOfoTYw%40mail.gmail.com <https://groups.google.com/d/msgid/ansible-project/CAMO4JZvLGMqY29JtWBSgkGi9_8ZVijv6HwXWjevm%2BQCWOfoTYw%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.


OpenPGP_signature

Roberto Paz

unread,
Dec 24, 2021, 7:48:32 AM12/24/21
to Ansible Project
My two cents: if you have pretty much the whole action you want as part of a already existent shell script who runs smoothly, maybe the best approach is to:

1) Copy script to remote managed server
2) Run script remotely using "shell" module.

Off course this is a lame use of ansible, but trying to embeed a full script into a single call for the shell module will be probably a bigger pain.

Eventually in time you can try to replace some of the shell steps with native ansible call to make a good use of it.

Reply all
Reply to author
Forward
0 new messages