{"id":164,"date":"2016-12-02T20:46:47","date_gmt":"2016-12-02T18:46:47","guid":{"rendered":"http:\/\/www.petersplanet.nl\/?p=164"},"modified":"2016-12-04T16:29:34","modified_gmt":"2016-12-04T14:29:34","slug":"launch-an-amazon-aws-instance-with-ansible","status":"publish","type":"post","link":"https:\/\/www.petersplanet.nl\/index.php\/2016\/12\/02\/launch-an-amazon-aws-instance-with-ansible\/","title":{"rendered":"Launch an Amazon AWS instance with Ansible"},"content":{"rendered":"<p>It is also possible to use Ansible to create an instance on Amazon AWS. I have used the Ansible EC2 Cloud Module to create a CentOS 7 Linux instance. See\u00a0<a href=\"http:\/\/docs.ansible.com\/ansible\/list_of_cloud_modules.html.\">http:\/\/docs.ansible.com\/ansible\/list_of_cloud_modules.html.<br \/>\n<\/a><!--more--><\/p>\n<p>I first set some environment variables for AWS. Like this:<\/p>\n<pre>export EC2_URL=https:\/\/ec2.amazonaws.com\r\nexport AWS_ACCESS_KEY_ID=\"XXXX\"\r\nexport AWS_SECRET_ACCESS_KEY=\"XXXXXXXXXX\"\r\nexport AWS_REGION=\"eu-west-1\"\r\n<\/pre>\n<p>Then I created a playbook\u00a0create-aws-centos.yml to launch a new AWS instance with CentOS.<\/p>\n<pre>- hosts: localhost\r\n  connection: local\r\n  gather_facts: yes\r\n  tasks:\r\n  - name: Create image\r\n    ec2:\r\n      key_name: xxxxx-keypair-eu-ie\r\n      group: default\r\n      instance_type: t2.micro\r\n      image: ami-7abd0209\r\n      wait: yes\r\n      wait_timeout: 500\r\n      count: 1\r\n      region: eu-west-1\r\n      state: present\r\n      volumes:\r\n      - device_name: \/dev\/sda1\r\n        volume_type: gp2\r\n        volume_size: 8\r\n      vpc_subnet_id: subnet-0ed78757\r\n      assign_public_ip: yes\r\n    register: ec2\r\n\r\n  - debug:\r\n      var: ec2\r\n<\/pre>\n<p>The command used to launch the playbook:<\/p>\n<pre>ansible-playbook create-aws-centos.yml -vvv\r\n<\/pre>\n<p>Now you can verify the result in the EC2 Management Console at the Instances.<\/p>\n<p>References:<br \/>\n<a href=\"https:\/\/aws.amazon.com\/\">https:\/\/aws.amazon.com\/<br \/>\n<\/a><a href=\"http:\/\/docs.ansible.com\/ansible\/\">https:\/\/docs.ansible.com\/ansible\/<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is also possible to use Ansible to create an instance on Amazon AWS. I have used the Ansible EC2 Cloud Module to create a CentOS 7 Linux instance. See\u00a0http:\/\/docs.ansible.com\/ansible\/list_of_cloud_modules.html.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":6,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/164\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}