# Need help on ansible code from shell script

**URL:** <https://forum.ansible.com/t/need-help-on-ansible-code-from-shell-script/36821>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [July 9, 2022, 11:00am UTC](https://forum.ansible.com/t/need-help-on-ansible-code-from-shell-script/36821 "2022-07-09T11:00:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [July 9, 2022, 11:00am UTC](https://forum.ansible.com/t/need-help-on-ansible-code-from-shell-script/36821/1 "2022-07-09T11:00:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [July 9, 2022, 4:44pm UTC](https://forum.ansible.com/t/need-help-on-ansible-code-from-shell-script/36821/2 "2022-07-09T16:44:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [July 9, 2022, 6:13pm UTC](https://forum.ansible.com/t/need-help-on-ansible-code-from-shell-script/36821/3 "2022-07-09T18:13:36Z")

</div>

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
