[ansible-project] Need help on ansible code from shell script

10 views
Skip to first unread message

Prady A

unread,
Jul 9, 2022, 7:01:42 AM7/9/22
to ansible...@googlegroups.com
Hi Experts,

Just started learning ansible few weeks back. want to automate a shell script. Need your help badly. Any jinja template or any help would be greatly appreciated.

Here is the pseudocode for the shell script

RHEL7_ENTRY1 -= "Algorithim-abc-xyz"
RHEL7_ENTRY2 -= "Cipher- cxyx-dfas"
MULTIPLE_ENTRY1= `grep -i  Cipher /etc/ssh/sshd_config | wc -l`
$SSHD_FILE  = /etc/ssh/sshd_config

If (OS== RHEL7) 
    Print (Redhat 7 >> to the logfile)
        If $RHEL7_ENTRY1 found in /etc/ssh/sshd_config file 
             print ( "Entry 1 found Ifgnoring changes " >> to the logfile)
             if($MULTIPLE_ENTRY -gt 1)
               1. Delete the old/duplicate entry of "Algorithm" from sshd_config file
                          sed -i '/Algothims/d' $SSHD_FILE   
                          sed -i '/Ciphers/d' $SSHD_FILE
               2. Add the new key(RHEL7_ENTRY1 & RHEL_ENTRY2) to the sshd_cofig file
                          sed -i "$a $RHEL7_ENTRY1" $SSHD FILE
                          sed -i "$a $RHEL7_ENTRY2" $SSHD_FILE
         else
             1. Print First entry does not match >> logfile
             2. remove any line if match to the string "Cipher"
             3. Add RHEL7_ENTRY1 to sshd_config file
          if (RHEL7_ENTRY2) found in sshd_config file
               Print  Entry2 found Ignoring changes >> logfile
           else
               print "2nd Entry not an exact match updating the file >> logfile
               remove the line containing the string "Cipher"
               Add the new key(RHEL_ENTRY2) to the sshd_cofig file
  fi 

And I ve to run the same for RHEL6, 7, 8 and Amazon Linux

Regards
          
    

Dick Visser

unread,
Jul 9, 2022, 12:44:43 PM7/9/22
to ansible...@googlegroups.com
What did you try already?
How does your playbook look like?


--
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/CAEuB3Ao3%3DcqX7mHUSXeEFWowveUHT80%2BLK%3D0ayPEZwm6R8A3jg%40mail.gmail.com.
--
Sent from Gmail Mobile

Prady A

unread,
Jul 9, 2022, 2:14:01 PM7/9/22
to ansible...@googlegroups.com
Hi

I  created the ansible code to create the log directory and file and the next thing I got stuck in the below code . I did not find any solution for if else condition in ansible . 

My folder structure is like below

Under roles
- tasks
- vars
- template 

Regards 

As of now I created files in tasks 

Reply all
Reply to author
Forward
0 new messages