# Bash to ansible

**URL:** <https://forum.ansible.com/t/bash-to-ansible/35895>\
**Category:** Ansible Project\
**Tags:** azure, vmware, aws\
**Created:** [October 19, 2021, 1:01am UTC](https://forum.ansible.com/t/bash-to-ansible/35895 "2021-10-19T01:01:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_Procopio](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Mario\_Procopio](https://forum.ansible.com/u/Mario_Procopio)\
**Post date:** [October 19, 2021, 1:01am UTC](https://forum.ansible.com/t/bash-to-ansible/35895/1 "2021-10-19T01:01:19Z")

</div>

Hi there.

I’m trying to use ansible to automate standard controls on redhat servers, I have several bash scripts that I currently run locally on each server so I can control them.

Script in bash

 ![pbash.PNG](https://us1.discourse-cdn.com/ansible/original/2X/1/16f9b0416bc32ec5da9ae835532612a140d30d5b.png)

today=`date`  
host=`hostname`  
version=`cat /etc/redhat-release`  
direccionip=`hostname -i`  
user=`whoami`  
azure=`systemd-detect-virt`  
echo “############################################################################################”  
echo “### HOSTNAME $host”  
echo “### VERSION $version”  
echo “### DIRECCION IP $direccionip”  
echo “### TIPO (AWS=kvm, zen o microsoft | Azure=hyper-v | Vmware=vmware) $azure”  
echo “### FECHA $today”  
echo “### USUARIO $user”  
echo “############################################################################################”  
echo " "  
echo “############################################################################################”  
echo “### 5.12 - Configure data retention ###”  
echo “############################################################################################”  
echo " "  
echo “### 5.12.6 - Collect privileged command usage ###”  
echo " "  
UIDMINVAL=$(/bin/awk ‘/^\s\*UID\_MIN/{print $2}’ /etc/login.defs); LINES=$(sudo find / -xdev -perm -4000 -o -perm -2000 -type f); for LINE in $LINES; do LINE1=“-a always,exit -F path=$LINE -F perm=x -F auid\>=$UIDMINVAL -F auid!=4294967295 -k privileged”; if [$(sudo cat /etc/audit/rules.d/audit.rules |/bin/egrep – “^$LINE1” | wc -l) -eq 0]; then LINE2=“-a always,exit -F path=$LINE -F perm=x -F auid\>=$UIDMINVAL -F auid!=4294967295 -k privileged”; if [$(sudo cat /etc/audit/rules.d/audit.rules |/bin/egrep – “^$LINE2” | wc -l) -eq 0]; then echo “$LINE2 - not found in /etc/audit/rules.d/audit.rules”; fi; fi; done  
echo " "  
echo “############################################################################################”  
echo “### Fin ###”  
echo “############################################################################################”

ere is my playbook that I am trying to put together in ansible. Everything works perfect, until I add line 12 and there it fails.

 ![ansible.PNG](https://us1.discourse-cdn.com/ansible/original/2X/3/3c105d88d79e8a2c8ca89e6a404d402a190d12ab.png)

- name: Shell Examples  
hosts: all  
tasks:
- name: Check Date with Shell command  
shell: |  
date  
hostname  
cat /etc/redhat-release  
hostname -i  
whoami  
systemd-detect-virt  
UIDMINVAL=$(/bin/awk ‘/^\s\*UID\_MIN/{print $2}’ /etc/login.defs); LINES=$(sudo find / -xdev -perm -4000 -o -perm -2000 -type f); for LINE in $LINES; do LINE1=“-a always,exit -F path=$LINE -F perm=x -F auid\>=$UIDMINVAL -F auid!=4294967295 -k privileged”; if [$(sudo cat /etc/audit/rules.d/audit.rules |/bin/egrep – “^$LINE1” | wc -l) -eq 0]; then LINE2=“-a always,exit -F path=$LINE -F perm=x -F auid\>=$UIDMINVAL -F auid!=4294967295 -k privileged”; if [$(sudo cat /etc/audit/rules.d/audit.rules |/bin/egrep – “^$LINE2” | wc -l) -eq 0]; then echo “$LINE2 - not found in /etc/audit/rules.d/audit.rules”; fi; fi; done  
register: fileout  
tags: fileout
- debug: msg=“{{ fileout.stdout\_lines }}”

From already thank you very much.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 19, 2021, 4:43am UTC](https://forum.ansible.com/t/bash-to-ansible/35895/2 "2021-10-19T04:43:42Z")

</div>

What is the reason you want to use ansible?

> **(attachments)**
>
> ![pbash.PNG](https://us1.discourse-cdn.com/ansible/original/2X/1/16f9b0416bc32ec5da9ae835532612a140d30d5b.png)  
> ![ansible.PNG](https://us1.discourse-cdn.com/ansible/original/2X/3/3c105d88d79e8a2c8ca89e6a404d402a190d12ab.png)
