November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

AWS with Ansible and Terraform

rmohan@root:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
rmohan@root:~$ python –version
Python 2.7.12

rmohan@root:~$ sudo apt-get install python-pip
Reading package lists… Done
Building dependency tree
Reading state information… Done
python-pip is already the newest version (8.1.1-2ubuntu0.4).
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
Use ‘sudo apt autoremove’ to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

rmohan@root:~$ pip install –upgrade pip
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |????????????????????????????????| 1.3MB 478kB/s
Installing collected packages: pip
Successfully installed pip-9.0.1

https://releases.hashicorp.com/terraform/

rmohan@root:~$ wget https://releases.hashicorp.com/terraform/0.11.3/terraform_0.11.3_linux_amd64.zip
–2018-03-08 11:55:25– https://releases.hashicorp.com/terraform/0.11.3/terraform_0.11.3_linux_amd64.zip
Resolving releases.hashicorp.com (releases.hashicorp.com)… 151.101.1.183, 151.101.65.183, 151.101.129.183, …
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.1.183|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 16466291 (16M) [application/zip]
Saving to: ‘terraform_0.11.3_linux_amd64.zip’

terraform_0.11.3_linux_amd64.zip 100%[==================================================================>] 15.70M 5.71MB/s in 2.8s

2018-03-08 11:55:29 (5.71 MB/s) – ‘terraform_0.11.3_linux_amd64.zip’ saved [16466291/16466291]

rmohan@root:~$ ls -l terraform_0.11.3_linux_amd64.zip
-rw-rw-r– 1 rmohan rmohan 16466291 Feb 1 02:23 terraform_0.11.3_linux_amd64.zip

rmohan@root:~$ sudo mkdir /bin/terraform

rmohan@root:~$ sudo unzip terraform_0.11.3_linux_amd64.zip -d /bin/terraform/
Archive: terraform_0.11.3_linux_amd64.zip
inflating: /bin/terraform/terraform

rmohan@root:~$ ls -l /bin/terraform/
total 67612
-rwxrwxr-x 1 root root 69233984 Jan 31 20:50 terraform

rmohan@root:~$ terraform –version
terraform: command not found

rmohan@root:~$ export PATH=$PATH:/bin/terraform/

rmohan@root:~$ terraform –version
Terraform v0.11.3

rmohan@root:~$ terraform
Usage: terraform [–version] [–help] [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you’re just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure
env Workspace management
fmt Rewrites config files to canonical format
get Download and install modules for the configuration
graph Create a visual graph of Terraform resources
import Import existing infrastructure into Terraform
init Initialize a Terraform working directory
output Read an output from a state file
plan Generate and show an execution plan
providers Prints a tree of the providers used in the configuration
push Upload this Terraform module to Atlas to run
refresh Update local state file against real resources
show Inspect Terraform state or plan
taint Manually mark a resource for recreation
untaint Manually unmark a resource as tainted
validate Validates the Terraform files
version Prints the Terraform version
workspace Workspace management

All other commands:
debug Debug output management (experimental)
force-unlock Manually unlock the terraform state
state Advanced state management

rmohan@root:~$ pip install awscli –upgrade

rmohan@root:~$ aws –version
aws-cli/1.11.13 Python/3.5.2 Linux/4.4.0-116-generic botocore/1.4.70

rmohan@root:~$ sudo apt-get install ansible

rmohan@root:~$ ansible –version
ansible 2.0.0.2
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

rmohan@root:~$ ssh-keygen

rmohan@root:~$ ssh-agent bash

rmohan@root:~$ ssh-add ~/.ssh/id_rsa
Identity added: /home/rmohan/.ssh/id_rsa (/home/rmohan/.ssh/id_rsa)

rmohan@root:~$ ssh-add -l
2048 SHA256:IQ9yajZaWP9O58/5Q8v3y8McEC8PGvjWw4tyX1mGqRY /home/rmohan/.ssh/id_rsa (RSA)

Uncomment the line

rmohan@root:~$ sudo vim /etc/ansible/ansible.cfg
host_key_checking = False

rmohan@root:~$ mkdir terraform_ansible

rmohan@root:~$ cd terraform_ansible/

rmohan@root:~/terraform_ansible$ aws configure
AWS Access Key ID [****************TAKA]:
AWS Secret Access Key [****************BklO]:
Default region name [us-east-1]:
Default output format [None]:

To check aws configured correctly
#############################################
rmohan@root:~/terraform_ansible$ aws ec2 describe-instances
{
“Reservations”: []
}

rmohan@root:~/terraform_ansible$ aws s3 ls
2018-03-07 09:26:12 elasticbeanstalk-us-east-1-536751915275
#############################################

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>