Unable to connect to ubuntu 16.04 using ansible - amazon-ec2

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

Related

How to run Ansible playbooks on Redhat Linux from Windows CLI?

I have a project where I have a cluster of Linux Redhat hosts, however I want to run a playbook through my Windows Command Prompt. I have checked out the documentation on their official website, but I didn't see much about my approach. I know it may not be conventional or smart to run it from a Windows CLI but I want to see if I could do it. I tried one line of code below:
Command:
ansible-playbook -i hosts playbook.yml
Using a stock windows machine as a control node is not supported.
There are however 2 options that will let you run ansible from windows:
Running from cygwin
Running from wsl (windows 10).

Amazon's aws cli times out on macOS 10.12.5

I just installed the aws cli (via pip install awscli per Amazon's installation instructions) on macOS 10.12.5. The installation completed without issue. But when I run the app (e.g. $ aws help) it just hangs for about a minute and finally fails with:
$ aws help
ssh: connect to host xxx.xxx.xxx.xxx port 22: Operation timed out
I've tried running it from both Python 3.6.1 and 2.7.13 environments. The macOS firewall is disabled so I'm not blocking any outbound requests.
I'm not sure what else to try at this point.
That is very strange behaviour. The AWS CLI does not activate ssh.
I would suggest that you have another script called aws somewhere in your PATH that you previously used to connect to an Amazon EC2 instance, and that script is running rather than the AWS CLI.
Run this command to discover which one it is running:
$ which aws
/usr/local/bin/aws
In this case, mine is in $ /usr/local/bin/aws help, but yours is likely to be elsewhere.
To run the correct one, use:
$ /usr/local/bin/aws help

[Ansible][Fedora 24] DNF Module Requires python2-dnf but it is Already Installed

I have computers on an internal network that is not connected to the internet, and have copied the relevant rpm packages into my local dnf repository. I'm trying to get ansible's DNF module to install a program on another computer but it pops up an error message stating that python2-dnf is not installed. But when I try to install the program it is already installed. Anyone have an idea whats going wrong?
I've placed the error code below.
Background:
Ansible Control machine: Fedora 24 4.5.5-300.fc24.x86_64 GNU/LINUX
Ansible Client machine: Fedora 24 4.5.5-300.fc24.x86_64 GNU/LINUX
yum/dnf local repository: Centos 7 3.10.0-327.28.3.el7.x86_64 GNU/LINUX
[root#localhost ansible]# ansible all -m dnf -a "name=vim state=present"
192.168.10.10 | FAILED! => {
"changed": false,
"failed": true
, "msg": "python2-dnf is not installed, but it is required for the Ansible dnf module."
}
[root#localhost ansible]# yum install python2-dnf
Yum command has been deprecated, redirecting to '/usr/bin/dnf install python2-dnf'.
See 'man dnf' and 'man yum2dnf' for more information.
To transfer transaction metadata from yum to DNF, run:
'dnf install python-dnf-plugins-extras-migrate && dnf-2 migrate'
Last metadata expiration check: 0:12:08 ago on Tue Oct 18 04:57:11 2016.
Package python2-dnf-1.1.9-2.fc24.noarch is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
As pointed out by #GUIDO you need python2-dnf on the target host.
Ansible module documentation states:
Requirements (on host that executes module)
python >= 2.6
python-dnf
on host that executes module means in the context of Ansible the target host of the play, not the control host.

Install and Configure Ansible on AWS EC2 Redhat Instance

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.

How to install ansible-playbook on windows as host with vagrant

I am trying to orchestrate server with LEMP stack and other configuration. For this I'm using vagrant to up(manage) servers and Ansible for auto configuration and package installations. I'm using windows as host machine where ansible need to be installed and all *Nix machine would be guest which are going to be configured.
With pip I have successfully installed ansible in C:\Python27\Scripts
I am facing Problem in running ansible and ansible-playbook on windows. If any one has done this for windows machine, Please share article or way to accomplish.
http://www.azavea.com/blogs/labs/2014/10/running-vagrant-with-ansible-provisioning-on-windows/
I had gone through above article but its not working, Error
==> default: Running provisioner: ansible...
zsh:1: no such file or directory: /bin/ansible-playbook
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
In *Nix as guest all working excellent. But looking for support to do same in windows machine.
Using windows as the control machine is not supported. But you can have a pleasant experience using docker with boot2docker.
This will install a virtualbox VM guest on the windows machine, which you will be able to use to configure you vagrant boxes, for which you will have to configure the networking properly.
You can achieve this with cygwin. For scripts to do this have a look at:
https://github.com/taliesins/win-ansible
As an added bonus it adds the shims required to use Ansible from windows command prompt and from Vagrant.
From the documentation:
Currently Ansible can be run from any machine with Python 2 (version 2.7) or Python 3 (versions 3.5 and higher) installed. Windows isn’t supported for the control machine.
Generally speaking, if you are using a Windows host, you have 3 options. Listed in order of (my) preference:
Run Ansible from a Docker container
Run Ansible from WSL (if you're running on Windows 10). This Gist can help you with some further setup so that you don't have to invoke WSL to run Ansible.
Run Ansible from Cygwin

Resources