Ansible SSH issue with EC2

Ever got this issue with Ansible when connecting EC2

fatal: [ec2-54-255-44-71.ap-southeast-1.compute.amazonaws.com] => SSH encountered an unknown error. The output was:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/iapilgrim/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: auto-mux: Trying existing master
ControlPath too long

Here is doc from Ansible (http://docs.ansible.com/intro_configuration.html#control-path)

On some systems with very long hostnames or very long path names (caused by long user names or deeply nested home directories) this can exceed the character limit on file socket names (108 characters for most platforms). In that case, you may wish to shorten the string to something like the below:

control_path = %(directory)s/%%h-%%r

Edit ansible.cfg does help me.

[ssh_connection]
control_path = %(directory)s/%%h-%%r

Install WordPress in Windows with Laragon

In my first blog, I posted how easy to create Laravel5 application with Laragon.

How about other PHP web applications? Even easier.

Let’s walk-through how to setup WordPress easily with Laragon.

Launch LaragonRemember to start all services if they’re not running.

step1_createdb

Open phpmyadmin. Create wordpress database, I name it lara_wp

step1_createdb2

Download latest WordPress package from https://wordpress.org/download/

Use Laragon to open Root folder.

step2_copy_wp

Extract and copy wordpress to Root folder

step2_copy_wp_root

Stop and Start Laragon. Doing this to tell Laragon reload Root folder. Now you can see the wordpress application in Laragon. Click it.

step3_launch_wp

Laragon will launch WordPress in web browser. Follow the following screenshots. They’re quite clear.

setup_wp0

Enter database info.

setup_wp2_db

Next

setup_wp2_runinstall

Setup first site

setup_wp4_install

Login Page

wp_login

WordPress Admin

wp_admin

WP front end

wp_fe

Next is your turn to check out Laragon and WordPress features. Let me know any missing features. I will update.

Series

How to install Laragon and Laravel 5 on Windows
Install WordPress in Windows with Laragon
Install Drupal in Windows with Laragon (soon)
Master Cmder with Laragon (soon)
Virtual Hosts with Laragon (soon)
Laragon: Redis is your friend (soon)
Laragon: Memcached I’m not dead yet (soon)

 

References:

EC2 Helper – Get private ip of an EC instance

I’m not good at bash script but sometimes I have to do with it.

The following codes to get private ip of an EC2

EC2_INS=i-72cf425a
PRIVATE_HOST=$(/opt/aws/bin/ec2-describe-instances $EC2_INS  --region ap-southeast-1 -O $AWS_ACCESS_KEY_ID -W $AWS_SECRET_ACCESS_KEY --headers | grep INSTANCE | awk {'print $5'})
IP_ADDR=$(getent hosts $PRIVATE_HOST | awk '{print $1}')

quite nice :).

Yet Another Rightscale Client

Our company is using RightScale.

I’m using RightScale Client API to orchestrate deployment to RightScale. This gem is cool except it requires a Python dev to write Ruby script.

I was sufferred with writing Ruby script ( I don’t blame Ruby, just blame myself not good at it) until I have found Tortilla.

Basic Tortilla ( From the github page)

Tortilla uses a bit of magic to wrap APIs. Whenever you get or call an attribute of a wrapper, the URL is appended by that attribute’s name or method parameter. Let’s say we have the following code:

id, count = 71, 20
api = tortilla.wrap('https://api.example.org')
api.video(id).comments.get(count)

Every attribute and method call represents a part of the URL:

api         -> https://api.example.org
.video      -> /video
(id)        -> /71
.comments   -> /comments
.get(count) -> /20
Final URL   -> https://api.example.org/video/71/comments/20

The last part of the chain (.get()) executes the request. It also (optionally) appends one last part to the URL. Which allows you to do stuff like this:

api.video.get(id)
# instead of this
api.video(id).get()

So to summarize, getting attributes is used to define static parts of a URL and calling them is used to define dynamic parts of a URL.

Once you’ve chained everything together, Tortilla will execute the request and parse the response for you.

Nice?

Except at the moment, Tortilla only accepts JSON-formatted responses. Supporting more formats is on the roadmap for future Tortilla versions.

My Cheat

https://github.com/pilgrim2go/tortilla/commit/0c38b4192eae137584d62f0f061eb4cdbe25a1c1

Yet Another Rightscale Client

rightscale.py

class RightScale(object):
    RS_ACCES_TOKEN = None
    def __init__(self):
        self.verbose = False
        self.home = os.getcwd()
        self.get_rs_authtoken()

    def get_rs_authtoken(self):

        if not RightScale.RS_ACCES_TOKEN:
            # magic strings from the 1.5 api
            DEFAULT_API_PREPATH = 'https://us-3.rightscale.com/api'

            # authenticate here
            OAUTH2_RES_PATH = '/'.join((DEFAULT_API_PREPATH, 'oauth2')) 
            login_data = {
                'grant_type': 'refresh_token',
                'refresh_token': os.getenv('RS_TOKEN'),
                }
            # client = self._client
            response = requests.post(OAUTH2_RES_PATH, data=login_data, headers={'X_API_VERSION':'1.5'})
            raw_token = response.json()
            RightScale.RS_ACCES_TOKEN =  "Bearer %s" % raw_token['access_token']

        return RightScale.RS_ACCES_TOKEN


    def get_rs_api(self,url='https://us-3.rightscale.com/api'):
        if not url:
            raise Exception('url can not be null')
        api = tortilla.wrap(url, extension='json',debug=True)
        api.headers.Authorization = self.get_rs_authtoken()
        api.headers.X_API_VERSION='1.5' 
        return api

And how to use it

Terminate a server

import rightscale.py
rs = RightScale()
rs.get_rs_api().servers(server_id).terminate.post(extension=None)

I use extension=None to cheat Tortilla to call as a norma POST request.

It’s just a cheat. We better to use extension=http or any meaning name in addition to ‘json’.

Just one liner to terminate a server. Dangerous :p

How to install Laragon and Laravel 5 on Windows

Laravel is a rapid web application development designed for Web artisans. Laravel 5 is just released with some cool features. Let check it out.

Since I’m using Windows so I’ll go with Laragon.

Why not XAMPP or WAMP?

Laragon is extremely fast, friendly menu, has all services we need ( Mysql, Memcached, Redis, Apache,..) and better than all it supports Laravel (4,5) as built-in features.

Why not Homestead?

Fine but remember to fix all issues here first.

https://laracasts.com/discuss?search=homestead

Ok. Let’s go

1) Download the latest Laragon here:

http://laragon.org/

Laragon 0.5
Laragon 0.5

2) Installation Laragon is straight-forward so needs no explanation. I have some screenshots for easy tracking.

setup_laragon0.5

setup_laragon0.5_2

At this step, you feel free to choose your formal working folder. Laragon is isolated and you can move it around after installing.

setup_laragon0.5_3

Laragon 0.5 provides cool feature to auto-detect working projects and create virtual host for you. Nice.

setup_laragon0.5_4

setup_laragon0.5_5

3) Run Laragon

run_laragon_menu

Choose Laravel > Create Project > Laravel 5

laragon-windows-10

run_laragon_menu3

See how Laragon bootstraps Laravel project behind the scene

run_laragon_menu4

It’s done

run_laragon_menu_done

What’s next?

Go to Laragon > Menu > Laravel > Switch Project > Valar

run_laragon_menu_valar

Note that Laragon automatically creates Virtual host for Valar application, starts Apache and Mysql and opens your default web browser.

run_laragon_finish

Ok. It’s basic setup for a Laravel 5 development environment in Windows with Laragon.

Enjoy !

Series

How to install Laragon and Laravel 5 on Windows
Install WordPress in Windows with Laragon
Install Drupal in Windows with Laragon (soon)
Master Cmder with Laragon (soon)
Virtual Hosts with Laragon (soon)
Laragon: Redis is your friend (soon)
Laragon: Memcached I’m not dead yet (soon)

References

Hello world!

van_pocket

It’s very new me. Hello 2015