Need help on ansible code from shell script

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_FILEelse

  3. Print First entry does not match >> logfile

  4. remove any line if match to the string “Cipher”

  5. 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

What did you try already?
How does your playbook look like?

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