Ansible: Up and Running

Ansible: Up and Running

Lorin Hochstein

Language: English

Pages: 334

ISBN: 1491915323

Format: PDF / Kindle (mobi) / ePub

Ansible: Up and Running

Lorin Hochstein

Language: English

Pages: 334

ISBN: 1491915323

Format: PDF / Kindle (mobi) / ePub


Among the many configuration management tools available, Ansible has some distinct advantages—it’s minimal in nature, you don’t need to install anything on your nodes, and it has an easy learning curve. This practical guide shows you how to be productive with this tool quickly, whether you’re a developer deploying code to production or a system administrator looking for a better automation solution.

Author Lorin Hochstein shows you how to write playbooks (Ansible’s configuration management scripts), manage remote servers, and explore the tool’s real power: built-in declarative modules. You’ll discover that Ansible has the functionality you need and the simplicity you desire.

  • Understand how Ansible differs from other configuration management systems
  • Use the YAML file format to write your own playbooks
  • Learn Ansible’s support for variables and facts
  • Work with a complete example to deploy a non-trivial application
  • Use roles to simplify and reuse playbooks
  • Make playbooks run faster with ssh multiplexing, pipelining, and parallelism
  • Deploy applications to Amazon EC2 and other cloud platforms
  • Use Ansible to create Docker images and deploy Docker containers

Beginning Database Design (Wrox Beginning Guides)

Professional C++ (2nd Edition)

Learning Swift: Building Apps for OS X and IOS

Embedded C

PHP Web Services (2nd Edition)

Linux Essentials (2nd Edition)

 

 

 

 

 

 

 

 

 

 

 

 

 

http://www.ubuntu.com/business/services/cloud 0 packages can be updated. 0 updates are security updates. Setting Up a Server for Testing | 13 Last login: Sun Aug 31 04:07:21 2014 from 10.0.2.2 Type exit to quit the SSH session. This approach lets us interact with the shell, but Ansible needs to connect to the vir‐ tual machine using the regular SSH client, not the vagrant ssh command. Tell Vagrant to output the SSH connection details by typing: $ vagrant ssh-config On my machine, the

used a dollar sign ($) to do variable inter‐ polation in playbooks instead of the braces. You used to derefer‐ ence variable foo by writing $foo, where now you write {{ foo }}. The dollar sign syntax has been deprecated; if you encounter it in an example playbook you find on the Internet, then you’re looking at older Ansible code. You can use all of the Jinja2 features in your templates, but we won’t cover them in detail here. Check out the Jinja2 Template Designer Documentation for more

hosts hosts: CentOS tasks: - name: install htop yum: name=htop # ... Although using group_by is one way to achieve conditional behavior in Ansible, I’ve never found much use for it. In Chapter 6, we’ll see an example of how to use the when task parameter to take different actions based on variables. That about does it for Ansible’s inventory. In the next chapter, we’ll cover how to use variables. See Chapter 9 for more details about ControlPersist, also known as SSH multiplexing. 68 | Chapter

We’ll be using this form of the debug module several times in this chapter. Registering Variables Often, you’ll find that you need to set the value of a variable based on the result of a task. To do so, we create a registered variable using the register clause when invok‐ ing a module. Example 4-2 shows how we would capture the output of the whoami command to a variable named login. Example 4-2. Capturing the output of a command to a variable - name: capture output of whoami command command:

Behaved Commands: changed_when and failed_when | 125 - fail: The output of the playbook when invoked the second time is Example 7-6. Example 7-6. Returned values when database has already been created TASK: [debug var=result] ****************************************************** ok: [default] => { "result": { "cmd": "python manage.py createdb --noinput --nodata", "failed": false, "failed_when_result": false, "invocation": { "module_args": '', "module_name": "django_manage" }, "msg":

Download sample

Download