Install and Configure Ansible on AWS EC2 Redhat Instance - amazon-ec2

I have just started learning Ansible configuration management tool and I was going through Linux Academy tutorials to run implement ansible commands, everything was good and easy with the linux-academy servers but when I tried to replicate the same in AWS EC2 instance i was unable to locate the "cd /etc/ansible/hosts". I have installed ansible using pip command i.e., "$sudo pip install ansible". I have been tried to resolve the issue but unable to find any proper documentation. The links I tried to install and configure ansible are as follows:
http://docs.ansible.com/ansible/intro_installation.html
http://www.cyberciti.biz/python-tutorials/linux-tutorial-install-ansible-configuration-management-and-it-automation-tool/
Guide me to configure the ansible hosts path to run the ansible commands and playbooks according to my requirements.

If you are using Ubuntu EC2 instance, follow this:
http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-apt-ubuntu
If you are using Amazon Linux EC2 instance, follow this:
http://docs.ansible.com/ansible/intro_installation.html#latest-release-via-yum
Installing via these package managers will create the /etc/ansible/hosts file for you.

Steps to install Ansible on EC2 instance [RHEL-8]:
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf config-manager --set-enabled codeready-builder-for-rhel-8-rhui-rpms
dnf install ansible
ansible --version
Use dnf for faster dependency resolution.

Related

Shade (python) module used by ansible needed but installed from yum not pip.

hi,
i am learning Openstack Newton and i'm building a lab. I have a pc which serves as controller and a Dell PowerEdge 2950 which will serve as compute node. I have another computer which will be the Ansible node. I made my first ansible playbook and tried to run it on the controller but i get an error (i need shade module installed on controlled).
Here is the problem. If i install shade using pip it messes with my openstack controller and the horizon dashboard is not accesible anymore, i get http error 500.
Is there a shade module in yum and how is it called?
thank you.
It's always better to use virtualenv to separate python contexts.
So create a virtualenv, activate it, install ansible and any necessary library (without messing up with the system python libraries) and launch ansible.
If you don't want to use ansible in a virtualenv, you can create one just for the task execution by setting ansible_python_interpreter for localhost (take a look at this answer).

Run brew restart command using Homebrew module for Ansible

I have been trying to run the command
brew services restart nrpe
with the help of Ansible's homebrew module.
I have gone through the documentation (homebrew ansible doc) but I couldn't find an example which does a similar thing. I have tried the following:
- homebrew:
name: nrpe
state: present
install_options: services,restart
but it didn't work. Please let me know the correct way to run the command
brew services restart nrpe.
P.S. - Installation of nrpe or other services though homebrew is working great.
Edit 1 - Also including the Nagios tag because this might also be faced by the nagios community.
According to the documentation of the homebrew ansible module, the command :
brew services restart nrpe
seems not implemented. The solution could be to use the command module:
- name: restart the nrpe service
command: brew services restart nrpe

Unable to connect to ubuntu 16.04 using ansible

I am using ansible playbook to create new AWS EC2 instance. I am running my playook from host1 and then want to run some tasks on newly created EC2 instance (host2). I am able to run all the ansible tasks if my EC2 ubuntu is 14.04 but it fails on ping if i change to ubuntu 16.04. I get below error when trying ping from host1 ansible host2 -m ping
"module_stdout": "/bin/sh: 1: /usr/bin/python2.7: not found\r\n",
I see couple of places it is mentioned that ubuntu 16.04 comes with python 3 and ansible does not support 3 yet hence we need to install ansible 2.7. My confusion is how can i installed python on my EC2 instance when ansible is failing to connect at the first place it self.
Any idea how can i around this?
Thanks,
Deepak
You can use the "raw" module to bootstrap the systems with Python 2.x.
e.g:
ansible host2 --sudo -m raw -a "apt-get install -y python2.7 python-simplejson"
Documentation: http://docs.ansible.com/ansible/intro_installation.html
http://serverascode.com/2016/08/16/ansible-python2-xenial.html
If your repositories don't have 2.7 you can install it from the deadsnakes repo, just add this ppa;
ppa:fkrull/deadsnakes-python2.7

Installing and Managing Jenkins on Amazon Linux

I'm looking to move Jenkins to Amazon EC2 running Amazon Linux.
Currently we have Jenkins installed as a package (via yum). I'm considering running Jenkins as the contained jenkins.war on EC2 (for auto-upgrades and ease of deployment).
Unfortunately I've been unable to find much documentation regarding managing jenkins as the latter.
I'm trying to determine:
Which installation is preferred, and why?
If running as a contained jar:
How do I start/stop jenkins?
Should I create a jenkins user?
Installation Steps :
Please launch an Amazon Linux instance using Amazon Linux AMI.
Login to your Amazon Linux instance.
Become root using “sudo su -” command.
Update your repositories
yum update
Get Jenkins repository using below command
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
Get Jenkins repository key
rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
Install jenkins package
yum install jenkins
Start jenkins and make sure it starts automatically at system startup
service jenkins start
chkconfig jenkins on
Open your browser and navigate to http://<Elastic-IP>:8080. You will see jenkins dashboard.
That’s it. You have your jenkins setup up and running. Now, you can create jobs to build the code.
Reference: http://sanketdangi.com/post/62715793234/install-configure-jenkins-on-amazon-linux
Jenkins Installation Ubuntu 14.04/16.01
Please follow the steps given below.
Switch to root user sudo su -
sudo apt-get update
sudo apt-get install default-jdk
sudo apt-get install default-jre
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt-get update
apt-get install jenkins
Get jenkins Password from:- vi /var/lib/jenkins/secrets/initialAdminPassword
Browse:- eg: 192.168.xx.xx:8080

AWS: Can't Bundle AMI

I am trying to create an AMIBundle following these instructions, but am running into an error. When I get to
ec2-bundle-vol -d /mnt -k /mnt/pk-XXX.pem -c /mnt/cert-YYY.pem -u 123456789012 -r i386 -p
rightscale_ami
and run it (using my correct variables, of course) I get: ERROR: You need to be root to run /vol/downloads/ec2-ami-tools-1.3-66634//lib/ec2/amitools/bundlevol.rb
I am not sure what the problem is. I tried changing the permissions around, but to no avail.
I am running Ubuntu 11.04 Server on a large instance, have installed the ec2 AMI and ec2 API tools, added them to path and their respective environment variables, and have done sudo aptitude install ruby. Maybe I need something else with ruby? Please help! Thanks.
I ended up installing the ami and api tools from the multiverse package within Ubuntu's apt manager. When I installed the tools this way, I could correctly do a sudo to run as root, whereas when I ran it originally it looked like the super user couldn't get access to my environment variables.

Resources