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 On Sun, Jul 10, 2022 at 1:44, Dick Visser <[email protected]> wrote: > What did you try already? > How does your playbook look like? > > > On Sat, 9 Jul 2022 at 13:01, Prady A <[email protected]> wrote: > >> 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 >> >> >> >> -- >> 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/CAEuB3Ao3%3DcqX7mHUSXeEFWowveUHT80%2BLK%3D0ayPEZwm6R8A3jg%40mail.gmail.com >> <https://groups.google.com/d/msgid/ansible-project/CAEuB3Ao3%3DcqX7mHUSXeEFWowveUHT80%2BLK%3D0ayPEZwm6R8A3jg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . > > >> -- > Sent from Gmail Mobile > > -- > 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/CAF8BbLZeFvbkbUw8u3wyAq1iB6NRdT6E9MXA5GQcNZJfP%2B24LA%40mail.gmail.com > <https://groups.google.com/d/msgid/ansible-project/CAF8BbLZeFvbkbUw8u3wyAq1iB6NRdT6E9MXA5GQcNZJfP%2B24LA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEuB3Arv3-0PxirhQ6-BJWo36Y0WSADozfzkHUzQsk--Lc_5wA%40mail.gmail.com.
