Giter Club home page Giter Club logo

ansible-auto-scaling-tutorial's People

Contributors

babatundebusari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-auto-scaling-tutorial's Issues

ERROR: ec2_ami_find is not a legal parameter in an Ansible task or handler

Hi,

I stumbled upon your tutorial and tried it but found the following issue when I launched the command
ansible-playbook deploy.yml -vv with the version 1.9.x of ansible

$ ansible-playbook deploy.yml -vv -i ../learn-ansible/hosts 
ERROR: ec2_ami_find is not a legal parameter in an Ansible task or handler

It works well with the version 2.0 though since the parameter ec2_ami_find has been implemented for the version 2.0.

Thanks for your tuto!

Failed to import module using ansible 1.9

I'm running ansible 1.9 and after importing the module to the library/ i get the below error http://pastie.org/10343625
My playbook looks like

  • name: Get latest ami based on date
    local_action:
    module: ec2_ami_find
    region: "{{ region }}"
    name: "ansible-created-{{ timestamp.stdout }}"
    owner: "{{ owner }}"
    sort: name
    sort_order: descending
    sort_end: 1
    register: existing_ami

Some folks on the ansible irc channel suggested that the modules of v1 would not work with v2 and use aws sdk calls or make the module v2 compatbile

build-ami variable not defined

Hi There. Loving this tutorial, however I have come accross an error when trying to build the ami.

The error I receive is:

TASK [build-ami : Create AMI] ************************************************** fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ec2_id' is undefined\n\nThe error appears to have been in '/etc/ansible/roles/build-ami/tasks/main.yml': line 4, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create AMI\n ^ here\n"}

Do you know where this variable is supposed to be set?

Adrian

playbook is failing

I am getting this error when playbook is launched

ASK [launch : Launch new instance] ********************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "The following group names are         
not valid: sg-xxxxxx"}

What is the hint for the security group here? must the security group be for the EC2-classic platform or it can be EC2-VPC platform as well?
Any more information needed to understand what SG to insert?

Thanks

failure with lc_find

First of all I really like this playbook, it's a really great tutorial. The one issue I have is when I try to run the custom module lc_find. I am passing the

ESTABLISH LOCAL CONNECTION FOR USER: douggrainger
localhost EXEC ( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1458078036.19-221905393396085 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1458078036.19-221905393396085 )" )
localhost PUT /var/folders/y_/nxy2vpcs3d5_jztrfg2sn8t00000gn/T/tmpBgwMXq TO /Users/douggrainger/.ansible/tmp/ansible-tmp-1458078036.19-221905393396085/lc_find
localhost EXEC LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /Users/douggrainger/.ansible/tmp/ansible-tmp-1458078036.19-221905393396085/lc_find; rm -rf "/Users/douggrainger/.ansible/tmp/ansible-tmp-1458078036.19-221905393396085/" > /dev/null 2>&1
fatal: [172.16.1.44 -> localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "lc_find"}, "module_stderr": "\nUnknown output type: None\nTraceback (most recent call last):\n File "/Users/douggrainger/.ansible/tmp/ansible-tmp-1458078036.19-221905393396085/lc_find", line 2219, in \n main()\n File "/Users/douggrainger/.ansible/tmp/ansible-tmp-1458078036.19-221905393396085/lc_find", line 31, in main\n lc_cmd_result = subprocess.check_output(["aws", "autoscaling", "describe-launch-configurations", "--region", module.params.get('region')])\n File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 573, in check_output\n raise CalledProcessError(retcode, cmd, output=output)\nsubprocess.CalledProcessError: Command '['aws', 'autoscaling', 'describe-launch-configurations', '--region', 'us-east-1']' returned non-zero exit status 255\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}.

These are the parameters i'm passing

  • name: Find Old Launch Configuration
    sudo: false
    local_action:
    module: lc_find
    region: 'us-east-1'
    name_regex: "{{rails_env}}-{{role}}-lc-*"
    sort: yes
    sort_end: -2
    register: old_lc_result

Installing boto

In my case

pip install -U python-boto
Collecting python-boto
  Could not find a version that satisfies the requirement python-boto (from versions: )
No matching distribution found for python-boto

but

pip install -U boto
Collecting boto
  Using cached https://files.pythonhosted.org/packages/23/10/c0b78c27298029e4454a472a1919bde20cb182dab1662cec7f2ca1dcc523/boto-2.49.0-py2.py3-none-any.whl
Installing collected packages: boto
Successfully installed boto-2.49.0

Proposition: change python-boto to boto. I do not know why, so anyone can explain?

https://stackoverflow.com/questions/2481287/how-do-i-install-boto

Does not work with ALB

This stuff is awesome. But I've recently moved to Application Load Balancers in my ASG's and you can't update an ASG when it's backed by an ALB instead of an ELB.

some minor issues I had to patch

Ciao,

very very nice work, congratulations!

Eventually I made it to work, albeit it does not delete old AMIs and old LCs. For LCs is because I had to change the name of them from a variable one (webapp-timestamp) to a fixed one (webapp), because with the variable name the creation of autoscaling group does not work (because it requires the name of the launch config).

I will try to fix that too, as time permit.

Tested with ansible 1.9.4 Python 2.7.9

I attach a git diff and app.js file (app.js because it does not need express framework).

Can you have a look at the diff and let me know your comments?

-giovanni
attachments follow:

============================================
// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
============================================


diff --git a/deploy.yml b/deploy.yml
index 765f69b..02aac42 100644
--- a/deploy.yml
+++ b/deploy.yml
@@ -26,11 +26,11 @@
   connection: local
   gather_facts: no
   roles:
-    - create-ami
+    - build-ami
     - create-launch-configuration
     - load-balancer
     - auto-scaling
-    - dns
+#    - dns

 - hosts: localhost
   connection: local
diff --git a/group_vars/all.yml b/group_vars/all.yml
index 7eb859f..df61994 100644
--- a/group_vars/all.yml
+++ b/group_vars/all.yml
@@ -1,14 +1,15 @@
 ---
 # group_vars/all.yml
-
-region: us-east-1
-zone: us-east-1a
-keypair: YOUR_KEYPAIR
-security_groups: YOUR_SECURITY_GROUP
+ansible_ssh_user: ubuntu
+region: eu-west-1
+zone: eu-west-1a
+keypair: audiens-01
+#security_groups: sg-a4774fc1
+security_groups: default
 instance_type: m3.medium
 volumes:
   - device_name: /dev/sda1
     device_type: gp2
     volume_size: 20
     delete_on_termination: true
-domain: YOUR_DOMAIN_NAME
+domain: "ciao.org"
diff --git a/roles/auto-scaling/tasks/main.yml b/roles/auto-scaling/tasks/main.yml
index a7f8cc4..4cf5d84 100644
--- a/roles/auto-scaling/tasks/main.yml
+++ b/roles/auto-scaling/tasks/main.yml
@@ -10,11 +10,17 @@
     asg_properties: "{{ (asg_properties_result.stdout | from_json).AutoScalingGroups[0] }}"
   when: (asg_properties_result.stdout | from_json).AutoScalingGroups | count

+- name: Set asg_properties variable from DEAD AIR output if the Auto Scaling Group NOT already exists
+  set_fact:
+    asg_properties: "{{ 0 }}"
+  when: not (asg_properties_result.stdout | from_json).AutoScalingGroups | count
+
+
 - name: Configure Auto Scaling Group and perform rolling deploy
   ec2_asg:
     region: "{{ region }}"
-    name: webapp
-    launch_config_name: webapp
+    name: "webapp"
+    launch_config_name: "webapp"
     availability_zones: "{{ zone }}"
     health_check_type: ELB
     health_check_period: 300
@@ -32,7 +38,7 @@
   ec2_scaling_policy:
     region: "{{ region }}"
     name: "{{ item.name }}"
-    asg_name: webapp
+    asg_name: "webapp"
     state: present
     adjustment_type: "{{ item.adjustment_type }}"
     min_adjustment_step: "{{ item.min_adjustment_step }}"
@@ -53,13 +59,14 @@

 - name: Determine Metric Alarm configuration
   set_fact:
+    asg_name: "webapp"
     metric_alarms:
-      - name: "{{ asg_name }}-ScaleUp"
+      - name: "webapp-ScaleUp"
         comparison: ">="
         threshold: 50.0
         alarm_actions:
           - "{{ sp_result.results[0].arn }}"
-      - name: "{{ asg_name }}-ScaleDown"
+      - name: "webapp-ScaleDown"
         comparison: "<="
         threshold: 20.0
         alarm_actions:
@@ -79,8 +86,8 @@
     evaluation_periods: 5
     unit: "Percent"
     dimensions:
-      AutoScalingGroupName: "{{ asg_name }}"
+      AutoScalingGroupName: "webapp"
     alarm_actions: "{{ item.alarm_actions }}"
   with_items: metric_alarms
-  when: max_size > 1
+  when: 10 > 1
   register: ma_result
diff --git a/roles/create-launch-configuration/tasks/main.yml b/roles/create-launch-configuration/tasks/main.yml
index d535c2b..4cb6aca 100644
--- a/roles/create-launch-configuration/tasks/main.yml
+++ b/roles/create-launch-configuration/tasks/main.yml
@@ -4,7 +4,8 @@
 - name: Create Launch Configuration
   ec2_lc:
     region: "{{ region }}"
-    name: "webapp-{{ ansible_date_time.iso8601 | regex_replace('[^a-zA-Z0-9]', '-') }}"
+#    name: "webapp-{{ ansible_date_time.iso8601 | regex_replace('[^a-zA-Z0-9]', '-') }}"
+    name: "webapp"
     image_id: "{{ ami.image_id }}"
     key_name: "{{ keypair }}"
     instance_type: "{{ instance_type }}"
diff --git a/roles/deploy/tasks/main.yml b/roles/deploy/tasks/main.yml
index a54fbb2..b6b0023 100644
--- a/roles/deploy/tasks/main.yml
+++ b/roles/deploy/tasks/main.yml
@@ -7,24 +7,36 @@
     state: present
   sudo: yes

+- name: Install node.js
+  apt:
+    pkg: nodejs
+    state: present
+  sudo: yes
+
+- name: Install nodejs-legacy
+  apt:
+    pkg: nodejs-legacy
+    state: present
+  sudo: yes
+
 - name: Create www directory
   file:
-    path: /srv/www
+    path: /srv/www/webapp
     owner: ubuntu
     group: ubuntu
     state: directory
   sudo: yes

-- name: Clone repository
-  git:
-    repo: "https://github.com/atplanet/hello-world-express-app.git"
-    dest: /srv/www/webapp
-    version: master
+- name: Install app.js
+  copy:
+    src: app.js
+    dest: /srv/www/webapp/app.js
+  sudo: yes

 - name: Install upstart script
   copy:
     src: upstart.conf
-    dest: /etc/upstart/webapp.conf
+    dest: /etc/init/webapp.conf
   sudo: yes

 - name: Enable and start the application
diff --git a/roles/nginx/files/nginx.conf b/roles/nginx/files/nginx.conf
index 22e6ef5..a402e55 100644
--- a/roles/nginx/files/nginx.conf
+++ b/roles/nginx/files/nginx.conf
@@ -1,4 +1,4 @@
-/nginx/files/nginx.conf
+# roles/nginx/files/nginx.conf

 server {
   listen 80 default_server;
diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml
index 73256fd..187ddb6 100644
--- a/roles/nginx/tasks/main.yml
+++ b/roles/nginx/tasks/main.yml
@@ -10,7 +10,7 @@
 - name: Configure Nginx
   copy:
     src: nginx.conf
-    dest: /etc/sites-enabled/default
+    dest: /etc/nginx/sites-enabled/default
   sudo: yes

 - name: Enable and start Nginx


=======================================

nginx role is not working

  • hosts: localhost
    connection: local
    gather_facts: no
    roles:

    • role: launch
      name: ami-build
  • hosts: ami-build
    roles:

    • nginx

it will not go to nginx role

TASK [launch : Wait for instance to boot] **************************************
task path: /home/anusha/ansible/test/roles/launch/tasks/main.yml:14
ok: [localhost] => (item={u'kernel': None, u'root_device_type': u'ebs', u'private_dns_name': u'ip-173-31-1-236.ap-
south-1.compute.internal', u'public_ip': u'35.154.213.1', u'private_ip': u'173.31.1.236', u'id': u'i-086f4ea1e971d
0a5d', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'hv.......

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0

Thanks

Invalid Action: DescribeLaunchConfigurations

I'm getting an issue with Launch Configuration while using Ansible's ec2_lc module. Listed below are few more details:

Backtrace
The full traceback is:
Traceback (most recent call last):
  File "/var/folders/b_/g8r_f0cx0bdb0vb5c2m55lth0000gn/T/ansible_jVpiEI/ansible_module_ec2_lc.py", line 498, in create_launch_config
    launch_configs = connection.describe_launch_configurations(LaunchConfigurationNames=[name]).get('LaunchConfigurations')
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/botocore/client.py", line 314, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/botocore/client.py", line 612, in _make_api_call
    raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidAction) when calling the DescribeLaunchConfigurations operation: The action DescribeLaunchConfigurations is not valid for this web service.

fatal: [localhost -> localhost]: FAILED! => {
    "changed": false,
    "error": {
        "code": "InvalidAction",
        "message": "The action DescribeLaunchConfigurations is not valid for this web service."
    }
...
Ansible Play
- name: Create Launch Configuration
  ec2_lc:
    region: "{{ region }}"
    name: "ansible-launch-config"
    image_id: "{{ image_id }}"
    instance_type: "{{ instance_type }}"
    security_groups: "{{ security_groups }}"
    state: present
System Details
ansible --version
ansible 2.5.0
boto version: 
import boto; print(boto.__version__)
2.48.0
awscli version:
import awscli; print(awscli.__version__)
1.14.63

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.