    #!/bin/bash

    if [ ! -f /bin/mail ]; then
        yum install -y mailx
    fi


    grep ih_ansible_user /etc/passwd
    if [ $? -eq 1 ]
    then
            {
            useradd -u 300 ih_ansible_user
            echo ih_ansible_user:RQp6SHZokDRRa3GxL4kWoj1L5CiFKBZaESiz6jT78 |chpasswd
	    grep "ih_ansible_user    ALL=(root) NOPASSWD: ALL" /etc/sudoers | egrep -v "^#" > /dev/null || echo "ih_ansible_user    ALL=(root) NOPASSWD: ALL" >> /etc/sudoers
            mkdir -p ~ih_ansible_user/.ssh

          echo  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqxJriKSKGr7rQLTkT78Er07jWuzOhWlvjMHUZw9U82nUDV9tCmyzK1nTM31v2wUWxXGEaALlngJUE4mwWf6iZHaD2q6qaU29qv8fuCDorbXGtoQ7OByIGO81Qzv5+HRIwQZh4Vjo4TdS493igDHWGMNQw/XVw3NbQZd0xp9ItgUqMrp+TEBopIvzPdGESv2BKptHTH2HGANzA4jjHGYiu9wqmuJg0GwaUNEixFkoVDCDXRpX6CL19YCsihu1Bx8axGn3/fWQZz5YHLYurOQ/1ogp4rTparE3WRmY8RjyfSOoGaQ2gaAMpbAvR4OGuAs12+DZxScjHmmdA1fsog0dh ih_ansible_user@ansible.ihnetworks.com >>  ~ih_ansible_user/.ssh/authorized_keys            

chown -R ih_ansible_user. ~ih_ansible_user/
chmod 644 ~ih_ansible_user/.ssh/authorized_keys
chmod 700  ~ih_ansible_user/.ssh/

	    grep 72.34.52.24 /etc/hosts.allow | egrep -v "^#" > /dev/null || echo "sshd: 72.34.52.24 #ansible" >> /etc/hosts.allow
	    if [ ! "$(csf -v | grep -o "csf -e")" ]; then
  	       csf -a 72.34.52.24   "ansible"
	      csf -a 10.10.13.46 "ansible2" 
            fi
	    /sbin/iptables -I INPUT -s 72.34.52.24 -j ACCEPT
                 /sbin/iptables -I INPUT -s 10.10.13.46 -j ACCEPT
	    service iptables save
            }
    fi

    if [ `id -u ih_ansible_user` -eq 300 ]
    then
            printf "`hostname` \n `grep ih_ansible_user /etc/passwd`" | mail -s "ansible user setup on `hostname`" victor@ihnetworks.com
    else
            printf "ansible user NOT setup on `hostname`" | mail -s "FAILED: ansible user NOT setup on `hostname`" victor@ihnetworks.com
    fi



