{"id":7317,"date":"2018-04-06T08:52:01","date_gmt":"2018-04-06T00:52:01","guid":{"rendered":"http:\/\/rmohan.com\/?p=7317"},"modified":"2018-04-06T08:52:01","modified_gmt":"2018-04-06T00:52:01","slug":"aws-with-ansible-and-terraform","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7317","title":{"rendered":"AWS with Ansible and Terraform"},"content":{"rendered":"<p>rmohan@root:~$ lsb_release -a<br \/>\nNo LSB modules are available.<br \/>\nDistributor ID: Ubuntu<br \/>\nDescription: Ubuntu 16.04.4 LTS<br \/>\nRelease: 16.04<br \/>\nCodename: xenial<br \/>\nrmohan@root:~$ python \u2013version<br \/>\nPython 2.7.12<\/p>\n<p>rmohan@root:~$ sudo apt-get install python-pip<br \/>\nReading package lists\u2026 Done<br \/>\nBuilding dependency tree<br \/>\nReading state information\u2026 Done<br \/>\npython-pip is already the newest version (8.1.1-2ubuntu0.4).<br \/>\nThe following packages were automatically installed and are no longer required:<br \/>\nlinux-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<br \/>\nUse \u2018sudo apt autoremove\u2019 to remove them.<br \/>\n0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.<\/p>\n<p>rmohan@root:~$ pip install \u2013upgrade pip<br \/>\nCollecting pip<br \/>\nDownloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)<br \/>\n100% |????????????????????????????????| 1.3MB 478kB\/s<br \/>\nInstalling collected packages: pip<br \/>\nSuccessfully installed pip-9.0.1<\/p>\n<p>https:\/\/releases.hashicorp.com\/terraform\/<\/p>\n<p>rmohan@root:~$ wget https:\/\/releases.hashicorp.com\/terraform\/0.11.3\/terraform_0.11.3_linux_amd64.zip<br \/>\n\u20132018-03-08 11:55:25\u2013 https:\/\/releases.hashicorp.com\/terraform\/0.11.3\/terraform_0.11.3_linux_amd64.zip<br \/>\nResolving releases.hashicorp.com (releases.hashicorp.com)\u2026 151.101.1.183, 151.101.65.183, 151.101.129.183, \u2026<br \/>\nConnecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.1.183|:443\u2026 connected.<br \/>\nHTTP request sent, awaiting response\u2026 200 OK<br \/>\nLength: 16466291 (16M) [application\/zip]<br \/>\nSaving to: \u2018terraform_0.11.3_linux_amd64.zip\u2019<\/p>\n<p>terraform_0.11.3_linux_amd64.zip 100%[==================================================================&gt;] 15.70M 5.71MB\/s in 2.8s<\/p>\n<p>2018-03-08 11:55:29 (5.71 MB\/s) \u2013 \u2018terraform_0.11.3_linux_amd64.zip\u2019 saved [16466291\/16466291]<\/p>\n<p>rmohan@root:~$ ls -l terraform_0.11.3_linux_amd64.zip<br \/>\n-rw-rw-r\u2013 1 rmohan rmohan 16466291 Feb 1 02:23 terraform_0.11.3_linux_amd64.zip<\/p>\n<p>rmohan@root:~$ sudo mkdir \/bin\/terraform<\/p>\n<p>rmohan@root:~$ sudo unzip terraform_0.11.3_linux_amd64.zip -d \/bin\/terraform\/<br \/>\nArchive: terraform_0.11.3_linux_amd64.zip<br \/>\ninflating: \/bin\/terraform\/terraform<\/p>\n<p>rmohan@root:~$ ls -l \/bin\/terraform\/<br \/>\ntotal 67612<br \/>\n-rwxrwxr-x 1 root root 69233984 Jan 31 20:50 terraform<\/p>\n<p>rmohan@root:~$ terraform \u2013version<br \/>\nterraform: command not found<\/p>\n<p>rmohan@root:~$ export PATH=$PATH:\/bin\/terraform\/<\/p>\n<p>rmohan@root:~$ terraform \u2013version<br \/>\nTerraform v0.11.3<\/p>\n<p>rmohan@root:~$ terraform<br \/>\nUsage: terraform [\u2013version] [\u2013help] [args]<\/p>\n<p>The available commands for execution are listed below.<br \/>\nThe most common, useful commands are shown first, followed by<br \/>\nless common or more advanced commands. If you\u2019re just getting<br \/>\nstarted with Terraform, stick with the common commands. For the<br \/>\nother commands, please read the help and docs before usage.<\/p>\n<p>Common commands:<br \/>\napply Builds or changes infrastructure<br \/>\nconsole Interactive console for Terraform interpolations<br \/>\ndestroy Destroy Terraform-managed infrastructure<br \/>\nenv Workspace management<br \/>\nfmt Rewrites config files to canonical format<br \/>\nget Download and install modules for the configuration<br \/>\ngraph Create a visual graph of Terraform resources<br \/>\nimport Import existing infrastructure into Terraform<br \/>\ninit Initialize a Terraform working directory<br \/>\noutput Read an output from a state file<br \/>\nplan Generate and show an execution plan<br \/>\nproviders Prints a tree of the providers used in the configuration<br \/>\npush Upload this Terraform module to Atlas to run<br \/>\nrefresh Update local state file against real resources<br \/>\nshow Inspect Terraform state or plan<br \/>\ntaint Manually mark a resource for recreation<br \/>\nuntaint Manually unmark a resource as tainted<br \/>\nvalidate Validates the Terraform files<br \/>\nversion Prints the Terraform version<br \/>\nworkspace Workspace management<\/p>\n<p>All other commands:<br \/>\ndebug Debug output management (experimental)<br \/>\nforce-unlock Manually unlock the terraform state<br \/>\nstate Advanced state management<\/p>\n<p>rmohan@root:~$ pip install awscli \u2013upgrade<\/p>\n<p>rmohan@root:~$ aws \u2013version<br \/>\naws-cli\/1.11.13 Python\/3.5.2 Linux\/4.4.0-116-generic botocore\/1.4.70<\/p>\n<p>rmohan@root:~$ sudo apt-get install ansible<\/p>\n<p>rmohan@root:~$ ansible \u2013version<br \/>\nansible 2.0.0.2<br \/>\nconfig file = \/etc\/ansible\/ansible.cfg<br \/>\nconfigured module search path = Default w\/o overrides<\/p>\n<p>rmohan@root:~$ ssh-keygen<\/p>\n<p>rmohan@root:~$ ssh-agent bash<\/p>\n<p>rmohan@root:~$ ssh-add ~\/.ssh\/id_rsa<br \/>\nIdentity added: \/home\/rmohan\/.ssh\/id_rsa (\/home\/rmohan\/.ssh\/id_rsa)<\/p>\n<p>rmohan@root:~$ ssh-add -l<br \/>\n2048 SHA256:IQ9yajZaWP9O58\/5Q8v3y8McEC8PGvjWw4tyX1mGqRY \/home\/rmohan\/.ssh\/id_rsa (RSA)<\/p>\n<p>Uncomment the line<\/p>\n<p>rmohan@root:~$ sudo vim \/etc\/ansible\/ansible.cfg<br \/>\nhost_key_checking = False<\/p>\n<p>rmohan@root:~$ mkdir terraform_ansible<\/p>\n<p>rmohan@root:~$ cd terraform_ansible\/<\/p>\n<p>rmohan@root:~\/terraform_ansible$ aws configure<br \/>\nAWS Access Key ID [****************TAKA]:<br \/>\nAWS Secret Access Key [****************BklO]:<br \/>\nDefault region name [us-east-1]:<br \/>\nDefault output format [None]:<\/p>\n<p>To check aws configured correctly<br \/>\n#############################################<br \/>\nrmohan@root:~\/terraform_ansible$ aws ec2 describe-instances<br \/>\n{<br \/>\n\u201cReservations\u201d: []<br \/>\n}<\/p>\n<p>rmohan@root:~\/terraform_ansible$ aws s3 ls<br \/>\n2018-03-07 09:26:12 elasticbeanstalk-us-east-1-536751915275<br \/>\n#############################################<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 \u2013version Python 2.7.12<\/p>\n<p>rmohan@root:~$ sudo apt-get install python-pip Reading package lists\u2026 Done Building dependency tree Reading state information\u2026 Done python-pip is already the newest version (8.1.1-2ubuntu0.4). The following packages were automatically installed and are [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7317"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7317"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7317\/revisions"}],"predecessor-version":[{"id":7318,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7317\/revisions\/7318"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}