**************************************************************************
* Description: Ansible installation on Linux, and create AWS EC2 instance
* Date: 04:06 PM EST, 04/18/2019
**************************************************************************

		 
<1> Install Ansible Package:
     |
     |__ $ yum install -y ansible
	 
	 
                 Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
                 rhui-REGION-client-config-server-7                                                                         | 2.9 kB  00:00:00
                 rhui-REGION-rhel-server-extras                                                                             | 3.4 kB  00:00:00
                 rhui-REGION-rhel-server-optional                                                                           | 3.2 kB  00:00:00
                 rhui-REGION-rhel-server-releases                                                                           | 3.4 kB  00:00:00
                 rhui-REGION-rhel-server-rh-common                                                                          | 3.8 kB  00:00:00
                 (1/6): rhui-REGION-rhel-server-extras/7Server/x86_64/updateinfo                                            | 169 kB  00:00:00
                 (2/6): rhui-REGION-rhel-server-extras/7Server/x86_64/primary_db                                            | 519 kB  00:00:00
                 (3/6): rhui-REGION-rhel-server-optional/7Server/x86_64/updateinfo                                          | 2.1 MB  00:00:00
                 (4/6): rhui-REGION-rhel-server-optional/7Server/x86_64/primary_db                                          | 7.5 MB  00:00:00
                 (5/6): rhui-REGION-rhel-server-releases/7Server/x86_64/updateinfo                                          | 3.0 MB  00:00:00
                 (6/6): rhui-REGION-rhel-server-releases/7Server/x86_64/primary_db                                          |  54 MB  00:00:01
                 Resolving Dependencies
                 --> Running transaction check
                 ---> Package ansible.noarch 0:2.4.2.0-2.el7 will be installed
                 --> Processing Dependency: python-cryptography for package: ansible-2.4.2.0-2.el7.noarch
                 --> Processing Dependency: python-httplib2 for package: ansible-2.4.2.0-2.el7.noarch
                 --> Processing Dependency: python-paramiko for package: ansible-2.4.2.0-2.el7.noarch
                 --> Processing Dependency: python-passlib for package: ansible-2.4.2.0-2.el7.noarch
                 --> Processing Dependency: python2-jmespath for package: ansible-2.4.2.0-2.el7.noarch
                 --> Processing Dependency: sshpass for package: ansible-2.4.2.0-2.el7.noarch
                 --> Running transaction check
                 ---> Package python-httplib2.noarch 0:0.9.2-1.el7 will be installed
                 ---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed
                 --> Processing Dependency: python2-pyasn1 for package: python-paramiko-2.1.1-9.el7.noarch
                 ---> Package python-passlib.noarch 0:1.6.5-2.el7 will be installed
                 ---> Package python2-cryptography.x86_64 0:1.7.2-2.el7 will be installed
                 --> Processing Dependency: python-cffi >= 1.4.1 for package: python2-cryptography-1.7.2-2.el7.x86_64
                 --> Processing Dependency: python-idna >= 2.0 for package: python2-cryptography-1.7.2-2.el7.x86_64
                 --> Processing Dependency: python-enum34 for package: python2-cryptography-1.7.2-2.el7.x86_64
                 ---> Package python2-jmespath.noarch 0:0.9.0-3.el7 will be installed
                 ---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
                 --> Running transaction check
                 ---> Package python-cffi.x86_64 0:1.6.0-5.el7 will be installed
                 --> Processing Dependency: python-pycparser for package: python-cffi-1.6.0-5.el7.x86_64
                 ---> Package python-enum34.noarch 0:1.0.4-1.el7 will be installed
                 ---> Package python-idna.noarch 0:2.4-1.el7 will be installed
                 ---> Package python2-pyasn1.noarch 0:0.1.9-7.el7 will be installed
                 --> Running transaction check
                 ---> Package python-pycparser.noarch 0:2.14-1.el7 will be installed
                 --> Processing Dependency: python-ply for package: python-pycparser-2.14-1.el7.noarch
                 --> Running transaction check
                 ---> Package python-ply.noarch 0:3.4-11.el7 will be installed
                 --> Finished Dependency Resolution
                 
                 Dependencies Resolved
                 
                 ==============================================================================================================================
                  Package                                   Arch             Version             Repository                               Size
                 ==============================================================================================================================
                 Installing:
                  ansible                                   noarch           2.4.2.0-2.el7       rhui-REGION-rhel-server-extras          7.6 M
                 Installing for dependencies:
                  python-cffi                               x86_64           1.6.0-5.el7         rhui-REGION-rhel-server-releases        218 k
                  python-enum34                             noarch           1.0.4-1.el7         rhui-REGION-rhel-server-releases         52 k
                  python-httplib2                           noarch           0.9.2-1.el7         rhui-REGION-rhel-server-extras          115 k
                  python-idna                               noarch           2.4-1.el7           rhui-REGION-rhel-server-releases         94 k
                  python-paramiko                           noarch           2.1.1-9.el7         rhui-REGION-rhel-server-releases        269 k
                  python-passlib                            noarch           1.6.5-2.el7         rhui-REGION-rhel-server-extras          488 k
                  python-ply                                noarch           3.4-11.el7          rhui-REGION-rhel-server-releases        123 k
                  python-pycparser                          noarch           2.14-1.el7          rhui-REGION-rhel-server-releases        105 k
                  python2-cryptography                      x86_64           1.7.2-2.el7         rhui-REGION-rhel-server-releases        503 k
                  python2-jmespath                          noarch           0.9.0-3.el7         rhui-REGION-rhel-server-extras           39 k
                  python2-pyasn1                            noarch           0.1.9-7.el7         rhui-REGION-rhel-server-releases        100 k
                  sshpass                                   x86_64           1.06-2.el7          rhui-REGION-rhel-server-extras           21 k
                 
                 Transaction Summary
                 ==============================================================================================================================
                 Install  1 Package (+12 Dependent packages)
                 
                 Total download size: 9.7 M
                 Installed size: 49 M                                                     
                 Downloading packages:                                                    
                 (1/13): python-cffi-1.6.0-5.el7.x86_64.rpm                                                                  | 218 kB  00:00:00
                 (2/13): python-httplib2-0.9.2-1.el7.noarch.rpm                                                              | 115 kB  00:00:00
                 (3/13): python-idna-2.4-1.el7.noarch.rpm                                                                    |  94 kB  00:00:00
                 (4/13): python-enum34-1.0.4-1.el7.noarch.rpm                                                                |  52 kB  00:00:00
                 (5/13): python-paramiko-2.1.1-9.el7.noarch.rpm                                                              | 269 kB  00:00:00
                 (6/13): python-passlib-1.6.5-2.el7.noarch.rpm                                                               | 488 kB  00:00:00
                 (7/13): python-ply-3.4-11.el7.noarch.rpm                                                                    | 123 kB  00:00:00
                 (8/13): python-pycparser-2.14-1.el7.noarch.rpm                                                              | 105 kB  00:00:00
                 (9/13): python2-cryptography-1.7.2-2.el7.x86_64.rpm                                                         | 503 kB  00:00:00
                 (10/13): python2-jmespath-0.9.0-3.el7.noarch.rpm                                                            |  39 kB  00:00:00
                 (11/13): python2-pyasn1-0.1.9-7.el7.noarch.rpm                                                              | 100 kB  00:00:00
                 (12/13): ansible-2.4.2.0-2.el7.noarch.rpm                                                                   | 7.6 MB  00:00:00
                 (13/13): sshpass-1.06-2.el7.x86_64.rpm                                                                      |  21 kB  00:00:00
                 -----------------------------------------------------------------------------------------------------------------------------------
                 Total                                                                                               14 MB/s | 9.7 MB  00:00:00
                 Running transaction check                                                
                 Running transaction test
                 Transaction test succeeded
                 Running transaction
                 Warning: RPMDB altered outside of yum.                                                 
                   Installing : python2-pyasn1-0.1.9-7.el7.noarch                                         1/13
                   Installing : python-enum34-1.0.4-1.el7.noarch                                          2/13
                   Installing : python-httplib2-0.9.2-1.el7.noarch                                        3/13
                   Installing : sshpass-1.06-2.el7.x86_64                                                 4/13
                   Installing : python2-jmespath-0.9.0-3.el7.noarch                                       5/13
                   Installing : python-passlib-1.6.5-2.el7.noarch                                         6/13
                   Installing : python-ply-3.4-11.el7.noarch                                              7/13
                   Installing : python-pycparser-2.14-1.el7.noarch                                        8/13
                   Installing : python-cffi-1.6.0-5.el7.x86_64                                            9/13
                   Installing : python-idna-2.4-1.el7.noarch                                             10/13
                   Installing : python2-cryptography-1.7.2-2.el7.x86_64                                  11/13
                   Installing : python-paramiko-2.1.1-9.el7.noarch                                       12/13
                   Installing : ansible-2.4.2.0-2.el7.noarch                                             13/13
                   Verifying  : python-idna-2.4-1.el7.noarch                                              1/13
                   Verifying  : python-pycparser-2.14-1.el7.noarch                                        2/13
                   Verifying  : python-ply-3.4-11.el7.noarch                                              3/13
                   Verifying  : python-passlib-1.6.5-2.el7.noarch                                         4/13
                   Verifying  : python-paramiko-2.1.1-9.el7.noarch                                        5/13
                   Verifying  : python2-jmespath-0.9.0-3.el7.noarch                                       6/13
                   Verifying  : ansible-2.4.2.0-2.el7.noarch                                              7/13
                   Verifying  : python-cffi-1.6.0-5.el7.x86_64                                            8/13
                   Verifying  : sshpass-1.06-2.el7.x86_64                                                 9/13
                   Verifying  : python-httplib2-0.9.2-1.el7.noarch                                       10/13
                   Verifying  : python2-pyasn1-0.1.9-7.el7.noarch                                        11/13
                   Verifying  : python-enum34-1.0.4-1.el7.noarch                                         12/13
                   Verifying  : python2-cryptography-1.7.2-2.el7.x86_64                                  13/13
                 
                 Installed:
                   ansible.noarch 0:2.4.2.0-2.el7
                 
                 Dependency Installed:
                   python-cffi.x86_64 0:1.6.0-5.el7             python-enum34.noarch 0:1.0.4-1.el7           
                   python-paramiko.noarch 0:2.1.1-9.el7         python-passlib.noarch 0:1.6.5-2.el7          
                   python2-cryptography.x86_64 0:1.7.2-2.el7    python2-jmespath.noarch 0:0.9.0-3.el7        
                   python-idna.noarch 0:2.4-1.el7               python-httplib2.noarch 0:0.9.2-1.el7
                   python-pycparser.noarch 0:2.14-1.el7         python-ply.noarch 0:3.4-11.el7      
                   sshpass.x86_64 0:1.06-2.el7                  python2-pyasn1.noarch 0:0.1.9-7.el7 
                 	
                 Complete!	



				 

<2> Verify Ansible Installation by Checking Version:
     |
     |__ $ ansible --version
	 
	 
                 ansible 2.4.2.0
                   config file = /etc/ansible/ansible.cfg
                   configured module search path = [u'/home/ec2-user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
                   ansible python module location = /usr/lib/python2.7/site-packages/ansible
                   executable location = /usr/bin/ansible
                   python version = 2.7.5 (default, Sep 12 2018, 05:31:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
	 
	
	
	
	
<3> Install Extra Package for Enterprise Linux, which would be needed by BOTO:
     |
     |__ $ yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
	 
	 
                 Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
                 epel-release-latest-7.noarch.rpm                                                                                            |  15 kB  00:00:00
                 Examining /var/tmp/yum-root-fHWhSU/epel-release-latest-7.noarch.rpm: epel-release-7-11.noarch
                 Marking /var/tmp/yum-root-fHWhSU/epel-release-latest-7.noarch.rpm to be installed
                 Resolving Dependencies
                 --> Running transaction check
                 ---> Package epel-release.noarch 0:7-11 will be installed
                 --> Finished Dependency Resolution
                 
                 Dependencies Resolved
                 
                 ======================================================================================================
                  Package                     Arch          Version        Repository                             Size
                 ======================================================================================================
                 Installing:
                  epel-release                noarch        7-11           /epel-release-latest-7.noarch          24 k
                 
                 Transaction Summary
                 ======================================================================================================
                 Install  1 Package
                 
                 Total size: 24 k
                 Installed size: 24 k
                 Is this ok [y/d/N]: y
                 Downloading packages:
                 Running transaction check
                 Running transaction test
                 Transaction test succeeded
                 Running transaction
                   Installing : epel-release-7-11.noarch                                          1/1
                   Verifying  : epel-release-7-11.noarch                                          1/1
                 
                 Installed:
                   epel-release.noarch 0:7-11
                 
                 Complete!
				 
				 
				 
				 
<4> Ensure EPEL got enbled:
     |
     |__ $ yum repolist
	 
	 
                 Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
                 epel/x86_64/metalink                                                                                                            |  16 kB  00:00:00
                 epel                                                                                                                            | 4.7 kB  00:00:00
                 (1/3): epel/x86_64/group_gz                                                                                                     |  88 kB  00:00:00
                 (2/3): epel/x86_64/updateinfo                                                                                                   | 986 kB  00:00:00
                 (3/3): epel/x86_64/primary_db                                                                                                   | 6.7 MB  00:00:00
                 repo id                                                  repo name                                                               status
                 epel/x86_64                                              Extra Packages for Enterprise Linux 7 - x86_64                          13,051
                 rhui-REGION-client-config-server-7/x86_64                Red Hat Update Infrastructure 2.0 Client Configuration Server 7              2
                 rhui-REGION-rhel-server-extras/7Server/x86_64            Red Hat Enterprise Linux Server 7 Extra(RPMs)                            1,076
                 rhui-REGION-rhel-server-optional/7Server/x86_64          Red Hat Enterprise Linux Server 7 Optional (RPMs)                       17,543
                 rhui-REGION-rhel-server-releases/7Server/x86_64          Red Hat Enterprise Linux Server 7 (RPMs)                                23,934
                 rhui-REGION-rhel-server-rh-common/7Server/x86_64         Red Hat Enterprise Linux Server 7 RH Common (RPMs)                         235
                 repolist: 55,841	 
				 
				 
				 

<5> Install python-pip, and it would be used to mount BOTO as command "pip":
     |
     |__ $ yum install python-pip
	 
	 
                 Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
                 Resolving Dependencies
                 --> Running transaction check
                 ---> Package python2-pip.noarch 0:8.1.2-8.el7 will be installed
                 --> Finished Dependency Resolution
                 
                 Dependencies Resolved
                 
                 =========================================================================================================
                  Package                         Arch               Version                  Repository             Size
                 =========================================================================================================
                 Installing:
                  python2-pip                     noarch             8.1.2-8.el7              epel                  1.7 M
                 
                 Transaction Summary
                 =========================================================================================================
                 Install  1 Package
                 
                 Total download size: 1.7 M
                 Installed size: 7.2 M
                 Is this ok [y/d/N]: y
                 \Downloading packages:
                 warning: python2-pip-8.1.2-8.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYs | 349 kB  --:--:-- ETA
                 Public key for python2-pip-8.1.2-8.el7.noarch.rpm is not installed
                 python2-pip-8.1.2-8.el7.noarch.rpm                                                                       | 1.7 MB  00:00:00
                 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
                 Importing GPG key 0x352C64E5:
                  Userid     : "Fedora EPEL (7) "
                  Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
                  Package    : epel-release-7-11.noarch (installed)
                  From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
                 Is this ok [y/N]: y
                 Is this ok [y/N]: y
                 Running transaction check
                 Running transaction test
                 Transaction test succeeded
                 Running transaction
                   Installing : python2-pip-8.1.2-8.el7.noarch                                                        1/1
                   Verifying  : python2-pip-8.1.2-8.el7.noarch                                                        1/1
                 
                 Installed:
                   python2-pip.noarch 0:8.1.2-8.el7
                 
                 Complete!



				 

<6> Install BOTO - Boto is a Python package that provides interfaces to Amazon Web Services:
     |
     |__ $ pip install boto
	 
	 
                 Collecting boto
                   Downloading https://files.pythonhosted.org/packages/23/10/boto-2.49.0-py2.py3-none-any.whl (1.4MB)
                     100% |███████████████████████████████| 1.4MB 857kB/s
                 Installing collected packages: boto
                 Successfully installed boto-2.49.0
                 You are using pip version 8.1.2, however version 19.0.3 is available.
                 You should consider upgrading via the 'pip install --upgrade pip' command.



				 
<7> Edit BOTO key file, and change permission:
     |
     |__ $ vi /home/ec2-user/.boto
     |
     |          [Credentials]
     |          aws_access_key_id = AKIAUAXOL8REPKDQANHZ
     |          aws_secret_access_key = JbPDK3jp6kFMi1TX8rlehIhdlasdfHx7UFK1djtvH
     |
     |
     |__ $ chmod 400 /home/ec2-user/boto





<8> Edit Ansible Playbook
     |
     |__ $ vi task_playboot.yml

	 
                 - name: ec2_launcher
                   hosts: localhost
                   connection: local
                   tasks:
                   - name: launching_ec2
                     ec2:
                       instance_type: t2.micro
                       key_name: FMW12C  
                       image: ami-011b3ccf1bd6db744
                       region: us-east-1
                       group: default
                       count: 2
                       vpc_subnet_id: subnet-12605c48
                       wait: yes
                       assign_public_ip: no 




<9> Create EC2 Instances according to Playbook:
     |
     |__ $ ansible-playbook /home/ec2-user/task_playbook.yml	  


                     [WARNING]: Could not match supplied host pattern, ignoring: all                   
                     [WARNING]: provided hosts list is empty, only localhost is available
                                       
                     PLAY [ec2_launcher] ************************************************************
                                                                                           
                     TASK [Gathering Facts] *********************************************************
                     ok:  [localhost]                                                       
                                                                                           
                     TASK [launching_ec2] ***********************************************************
                     changed: [localhost]
                     
                     PLAY RECAP *********************************************************************
                     localhost                  : ok=2    changed=1    unreachable=0    failed=0




<10> Reference:
     |
     |__ o. Youtube tutorial part 1 - https://www.youtube.com/watch?v=gEX1HbM4KSM
     |
     |__ o. Youtube tutorial part 2 - https://www.youtube.com/watch?v=zXp5PJ-xCGQ
     |
     |__ o. Enable EPEL for Linux - https://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/
     |
     |__ o. Install Python Pip - https://www.tecmint.com/install-pip-in-linux/
				 
    
	

Your Comments