Using BASH Scripting to install Ansible for a Nginx Install on AWS EC2 Instance

I came across this script I wrote a while back that was on my github. It’s an example how you canĀ  use Ansible playbooks along with simple bash scripting to bootstrap machines. It’s not exactly cutting edge but I enjoyed coming across it again:


#install ansible
yum install wget -y
rpm -ivh epel-release-7-8.noarch.rpm
yum install ansible -y

cd $HOME
mkdir -p ansible-nginx/tasks/
touch ansible-nginx/deploy.yml
touch ansible-nginx/tasks/install_nginx.yml

#populate deploy.yml

echo -e “# ./ansible-nginx/deploy.yml

– hosts: localhost
– include: ‘tasks/install_nginx.yml'” > $HOME/ansible-nginx/deploy.yml

#populate install_nginx.yml

echo -e “# ./ansible-nginx/tasks/install_nginx.yml

– name: NGINX | Installing NGINX repo rpm

– name: NGINX | Installing NGINX
name: nginx
state: latest

– name: NGINX | Starting NGINX
name: nginx
state: started
” > $HOME/ansible-nginx/tasks/install_nginx.yml


#install nginx
sudo ansible-playbook -c local $HOME/ansible-nginx/deploy.yml

#populate with index.html

echo -e “<html>
<title>NWEA tech_quiz sample index.html</title>
<body bgcolor=white>

<table border=”0″ cellpadding=”10″>
<h1>Hello, this is the sample page</h1>

</html>” > /usr/share/nginx/html/index.html

#edit default.conf to listen on port 8888
sed -i -e ‘s/80/8888/g’ /etc/nginx/conf.d/default.conf

#configure se linux to allow systemctl to function
semanage permissive -a “httpd_t”

#reload nginx
systemctl restart nginx.service