Ansible Fundamentals: Core Concepts with Simple Examples

Ansible is not magic, and it is not complicated. It is a declarative automation tool that answers one question:

“What should the system look like when I’m done?”

In two articles, you’ll learn the core concepts of Ansible and apply them through small, practical tasks.

We explain how to set up a fully functional WordPress website using Ansible to install and configure everything you need: PHP, a database, and a web server.

Continue reading Ansible Fundamentals: Core Concepts with Simple Examples

How to set the default SSH port for Ansible connections to 2222?

There are several methods to set the SSH port for Ansible.

Simplest one: Inventory variable

Edit your inventory file to add the port:

[myhosts]
host1 ansible_host=1.2.3.4 ansible_port=2222
host2 ansible_host=1.2.3.5 ansible_port=2222

Or make it default for a whole group:

[myhosts]
host1 ansible_host=1.2.3.4
host2 ansible_host=1.2.3.5

[myhosts:vars]
ansible_port=2222
Continue reading How to set the default SSH port for Ansible connections to 2222?

80 Most Useful Linux Commands

A
alias
The alias command lets you run a command or a series of Unix commands using a shorter name than the ones usually associated with them.

apt, apt-get
The apt-get tool automatically updates a Debian machine and installs Debian packages/programs.

awk, Gawk
AWK is a programming language tool used to manipulate text. The AWK utility resembles the shell programming language in many areas, but AWK’s syntax is very much its own. Gawk is the GNU Project’s version of the AWK programming language.

Continue reading 80 Most Useful Linux Commands

Ajax Request Monitoring in Chrome

In Firefox, you could use Firebug, which allows you to view every HTTP request that Ajax calls are making. How to view each Ajax request in Chrome Developer Tools?

How to view Ajax HTTP requests in Chrome

  1. Use CTRL+SHIFT+I (or navigate to Current Page Control > Developer > Developer Tools. In newer versions of Chrome, click the Wrench icon > Tools > Developer Tools to open Developer Tools.
  2. From within the developer tools, click on the Network button. If it isn’t already, will allow it for the session or always.
  3. Click the "XHR" sub-button.
  4. Initiate an AJAX call.
  5. You will see items begin to show up in the left column under "Resources".
  6. Click the resource, and two tabs show the headers and the return content.

How to view HTTP headers in Google Chrome

In Chrome, the Developer Tools “Network” tab shows different requests, and when you click one, you can see the headers on the right in a separate tab.

To show Chrome Developer Tools, press F12 or CTRL+SHIFT+I on Windows or ⌥⌘I on a Mac.

Python in 10 minutes

If you want to learn the Python programming language but can’t find a concise and yet full-featured tutorial – this tutorial will attempt to teach you Python in 10 minutes. It’s probably not so much a tutorial as it is a cross between a tutorial and a cheatsheet, so it will just show you some basic concepts to start you off. Obviously, if you want to really learn a language you need to program in it for a while. I will assume that you are already familiar with programming and will, therefore, skip most of the non-language-specific stuff. The important keywords will be highlighted so you can easily spot them. Also,pay attention because, due to the terseness of this tutorial, some things will be introduced directly in code and only briefly commented on. Continue reading Python in 10 minutes

How to get client IP address in PHP

Are you using $_SERVER[‘REMOTE_ADDR’] to find the the client’s IP address in PHP? Well dude, you might be amazed to know that it may not return the true IP address of the client at all time. If your client is connected to the Internet through Proxy Server then $_SERVER[‘REMOTE_ADDR’] in PHP just returns the the IP address of the proxy server not of the client’s machine. So here is a simple function in PHP to find the real IP address of the client’s machine. There are extra Server variable which might be available to determine the exact IP address of the client’s machine in PHP, they are HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR. Continue reading How to get client IP address in PHP

Check POST values in PHP

In some case you have to check what method was used to request your web page or check some values in POST parameters.

You have two options to check it using PHP.

1. Check if there’s ANY POST data at all

//Note: This resolves as true even if all $_POST values are empty strings
if (!empty($_POST))
{
    // handle post data
    $fromPerson = '+from%3A'.$_POST['fromPerson'];
    echo $fromPerson;
}

2. Only check if a PARTICULAR Key is available in post data

Try these PHP code to check some POST parameter:

if (isset($_POST['fromPerson']) )
{
    $fromPerson = '+from%3A'.$_POST['fromPerson'];
    echo $fromPerson;
}

Python 3

What are the differences?

Short version: Python 2.x is legacy, Python 3.x is the present and future of the language

Python 3.0 was released in 2008. The final 2.x version 2.7 release came out in mid-2010, with a statement of extended support for this end-of-life release. The 2.x branch will see no new major releases after that. 3.x is under active development and has already seen over five years of stable releases, including version 3.3 in 2012, 3.4 in 2014, and 3.5 in 2015. This means that all recent standard library improvements, for example, are only available by default in Python 3.x. Continue reading Python 3