Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to Install Ansible on Amazon Linux / CentOS?
sudo su
yum update
yum install -y git
cd /usr/local/src
yum -y install git python-jinja2 python-paramiko PyYAML make MySQL-python
git clone git://github.com/ansible/ansible.git
cd ansible
git submodule update --init --recursive
make install
CTRL + D
sudo echo "[localhost]" > ~/ansible_hosts
sudo echo "localhost ansible_connection=local" >> ~/ansible_hosts
export ANSIBLE_INVENTORY=~/ansible_hosts
sudo vim /etc/ansible/hosts 
[127.0.0.1]
127.0.0.1 ansible_connection=local

[localhost]
127.0.0.1 ansible_connection=local
export AWS_ACCESS_KEY_ID='AK123'
export AWS_SECRET_ACCESS_KEY='abc123'

[test.yml]

---
- name: implicit localhost test...
  hosts: localhost
  tasks:
  - debug: msg="hello world" 
ansible-playbook test.yml
@bam0382

This comment has been minimized.

Copy link

bam0382 commented Mar 25, 2016

Running the above gives the following error after make install

File "/tmp/easy_install-vN4O2U/pycrypto-2.6.1/setup.py", line 278, in run

RuntimeError: autoconf error
make: *** [install] Error 1

@diegopacheco

This comment has been minimized.

Copy link
Owner Author

diegopacheco commented Jul 7, 2016

@bam0382

did you install this ?

yum -y install git python-jinja2 python-paramiko PyYAML make MySQL-python

Are you running as root?

sudo su

@diegopacheco

This comment has been minimized.

Copy link
Owner Author

diegopacheco commented Aug 23, 2016

To Force use Ansible 2.0:

git clone git://github.com/ansible/ansible.git
cd ansible
git checkout -b stable-2.0 origin/stable-2.0
git submodule update --init --recursive
sudo make install

To Force use Ansible 2.1:

git clone git://github.com/ansible/ansible.git
cd ansible
git checkout -b stable-2.1 origin/stable-2.1
git submodule update --init --recursive
sudo make install

To Force use Ansible 2.3:

git clone https://github.com/ansible/ansible.git
cd ansible
git checkout -b stable-2.3 origin/stable-2.3
git submodule update --init --recursive
sudo make install

To Force use Ansible 2.4:

git clone https://github.com/ansible/ansible.git
cd ansible
git checkout -b stable-2.4 origin/stable-2.4
git submodule update --init --recursive
sudo make install

For ansible 2.7:

sudo python -m pip install -U pip
sudo pip install packaging

git clone https://github.com/ansible/ansible.git
cd ansible
git checkout -b stable-2.7 origin/stable-2.7
git submodule update --init --recursive
sudo make install
@diegopacheco

This comment has been minimized.

Copy link
Owner Author

diegopacheco commented Aug 23, 2016

Ansible Structure and Yaml format

-myproject
  - roles
    - redis
        - files
        - meta
        - tasks
            - main.yml
  -redis.yml

redis.yml

---

- hosts: 127.0.0.1
  sudo: yes

  vars:
    myvar: 10

  roles:
  - redis

Them in your main.yml you do like:

---

- name: ensure yum is updated
  action: yum name=* state=latest

- name:  ensure Git is present
  action: yum pkg=git state=present

Or.... if you dont want to import the role you can do:

---

- name: ensure yum is updated
  tasks:
  - action: yum name=* state=latest

- name:  ensure Git is present
  tasks:
  - action: yum pkg=git state=present
@aharden

This comment has been minimized.

Copy link

aharden commented Jul 11, 2017

I needed to also install libffi-devel and openssl-devel to "make install" on Amazon Linux 2017.03. Thanks.

@diegopacheco

This comment has been minimized.

Copy link
Owner Author

diegopacheco commented Nov 16, 2017

Cool @aharden

@diegopacheco

This comment has been minimized.

Copy link
Owner Author

diegopacheco commented Nov 16, 2017

Also could do (ansible 2.4):

playbook.yml

---

- hosts: localhost
  tasks:
  - name: Redis - Override default configs
    lineinfile:
      dest=/tmp/ansible-redis/out.txt
      state=present
      regexp="{{ item.regexp }}"
      line="{{ item.line }}"
      backrefs=yes
    with_items:
      - { regexp: 'daemonize yes', line: 'daemonize no' }
      - { regexp: 'dbfilename dump[.]rdb', line: 'dbfilename nfredis.rdb' }
      - { regexp: 'bind 0.0.0.0', line: 'bind 127.0.0.1' }
ansible-playbook -i localhost playbook.yml
@diegopacheco

This comment has been minimized.

Copy link
Owner Author

diegopacheco commented Dec 26, 2017

For CentOS / Amazon Linux -- You can just

sudo pip uninstall ansible
sudo pip install ansible
@diegopacheco

This comment has been minimized.

Copy link
Owner Author

diegopacheco commented Jun 14, 2018

I made a simple sandbox to run ansible locally in docker using amazon linux: https://github.com/diegopacheco/ansible-docker

@DemetriusTsitrelis

This comment has been minimized.

Copy link

DemetriusTsitrelis commented Jun 7, 2019

This works for me:

pip install --user ansible

@DemetriusTsitrelis

This comment has been minimized.

Copy link

DemetriusTsitrelis commented Jun 7, 2019

Or, as someone else just pointed out to me:

sudo amazon-linux-extras install ansible2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.