Ansible And Aws

Installation ubuntu 16.04 on vagrant environment

install by packet repos to resovle dependencies and install by git later

apt-get install ansible git
ansible --version
ansible 2.0.0.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

remove and install by git

apt-get remove ansible
git clone https://github.com/ansible/ansible.git --recursive
apt-get install python-setuptools make
cd ansible
make 
make install
 which ansible
/usr/local/bin/ansible

 /usr/local/bin/ansible --version
ansible 2.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

Ping test

change the ansible host file

:/etc/ansible$ sudo nano hosts
[control]
localhost

create a test user for auto login

sudo adduser test
sudo su - test
ssh-keygen
ssh-copy-id test@localhost

enable sudo access for the test user

sudo visudo
test    ALL=(ALL) NOPASSWRD: ALL

test if is working

test@vagrant-ubuntu-trusty-64:~$ ansible all -m ping
localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

install program

sudo apt-get install python-pip
sudo pip install awscli

Lecture: Module: EC2_Facts

nano awsec2facts.yml

--- # Gather EC2 Facts from my remote instance(s)

- host: aws
  remote_user: ec2-user
  become: yes
  connection: ssh
  gather_facts: yes
  tasks:
  - name: Gather the EC2 Facts about running instance(s)
    action: ec2_facts
  - name: Display the instance type
    debug: msg='{{ ansible_ec2_instance_type }}'

this will print the kind of ec2 type for all the machines

ansible-playbook awsec2facts.yml

to print only for machines with t2.micro change the task in this way

  tasks:
  - name: Gather the EC2 Facts about running instance(s)
    action: ec2_facts
  - name: Display the instance type
    debug: msg='{{ ansible_ec2_instance_type }}'
    when: ansible_ec2_instance_type == 't2.micro'
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License