Skip to content

Commit c2eab14

Browse files
committed
Merge pull request #1 from ellekrout/ansible
Small tech edit changes
2 parents fe48ed9 + a59e104 commit c2eab14

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

docs/websites/ansible/getting-started-with-ansible.md renamed to docs/applications/ansible/getting-started-with-ansible.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ modified_by:
1212
title: 'Getting Started with Ansible'
1313
contributor:
1414
name: Joshua Lyman
15-
link: [Twitter: @jlyman](https://twitter.com/jlyman)
15+
link: https://twitter.com/jlyman
1616
external_resources:
1717
- '[Ansible Home Page](http://www.ansible.com/home)'
1818
- '[Ansible Documentation](http://docs.ansible.com/ansible/index.html)'
@@ -21,14 +21,14 @@ external_resources:
2121

2222
## About Ansible
2323

24-
The drudge work of administering Lindoes: setting up a server, and especially multiple servers, keeping them all updated, pushing changes out to them, copying files, etc. Things can get complicated and time consuming very quickly, but it doesn't have to be that way. _[Ansible](http://www.ansible.com/home)_ is a very helpful tool that allows you to create groups of machines, describe how those machines should be configured or what actions should be taken on them, and issue all of these commands from a central location. It uses simple SSH, and so nothing is required to be installed on the machines you are targeting, needing only Ansible's installed files on your main control machine (can even be your laptop!). It is a simple solution to a complicated problem.
24+
The drudge work of administering Linodes: setting up a server, and especially multiple servers, keeping them all updated, pushing changes out to them, copying files, etc. Things can get complicated and time consuming very quickly, but it doesn't have to be that way. *[Ansible](http://www.ansible.com/home)* is a very helpful tool that allows you to create groups of machines, describe how those machines should be configured or what actions should be taken on them, and issue all of these commands from a central location. It uses simple SSH, and so nothing is required to be installed on the machines you are targeting, needing only Ansible's installed files on your main control machine (can even be your laptop!). It is a simple solution to a complicated problem.
2525

26-
In this guide you will be introduced to the basic of Ansible, and will get it installed and up and running. By the end of this guide, you'll have the tools needed to turn a brand new Linode VPS into a simple web server (Apache, MySQL, PHP), easily replicatable and adjustable. (And why not go ahead and try it? With Linode's hourly billing you can experiment with this guide for just a few cents.)
26+
In this guide you will be introduced to the basics of Ansible, and will get it installed and up and running. By the end of this guide, you'll have the tools needed to turn a brand new Linode VPS into a simple web server (Apache, MySQL, PHP), easily replicatable and adjustable. (And why not go ahead and try it? With Linode's hourly billing you can experiment with this guide for just a few cents.)
2727

2828

2929
## Installation
3030

31-
Ansible only needs to be installed on the _control machine_, or the machine from which you will be running commands. This will likely be your laptop or other computer from which you frequently access your server, or it may be a centralized server in more complicated setups.
31+
Ansible only needs to be installed on the *control machine*, or the machine from which you will be running commands. This will likely be your laptop or other computer from which you frequently access your server, or it may be a centralized server in more complicated setups.
3232

3333
Make sure that you have Python 2.x available on the control machine (Ansible is not compatible with Python 3, nor can you use Windows as the control machine). You can easily [build Ansible from source](https://github.com/ansible/ansible) as is frequently done, or you can install the latest stable packages using the proper command below.
3434

@@ -37,9 +37,13 @@ Make sure that you have Python 2.x available on the control machine (Ansible is
3737
sudo easy_install pip
3838
sudo pip install ansible
3939

40-
*CentOS/Fedora: install the epel-release RPM if needed on CentOS, RHEL, or Scientific Linux*
40+
*CentOS/Fedora:*
4141

4242
sudo yum install ansible
43+
44+
{: .note}
45+
>
46+
>The EPEL-Release repository may need to be added on certain versions of CentOS, RHEL, and Scientific Linux
4347
4448
*Ubuntu:*
4549

@@ -74,16 +78,16 @@ If you are successful you should see output similar to the following:
7478
"ping": "pong"
7579
}
7680

77-
Hooray! You were just able to get a valid connection to your server via Ansible! Now let's talk briefly about your _Inventory_ file and then move on to configuring the server via Ansible _Playbooks_.
81+
Hooray! You were just able to get a valid connection to your server via Ansible! Now let's talk briefly about your *Inventory* file and then move on to configuring the server via Ansible *Playbooks*.
7882

7983

8084
## Inventory File
8185

8286
You executed an Ansible command against your server, but it would be a pain to have to type the host's address every single time, and what if you had several servers you wanted to apply the same configuration to? This is where Ansible's [Inventory file](http://docs.ansible.com/ansible/intro_inventory.html) comes into play. By default, this file is expected to be located at `/etc/ansible/hosts`. Create that path and file if it does not already exist. If you are running OS X, you may want to create your own Ansible directory elsewhere and then set the path in an Ansible configuration file, as in the following:
8387

84-
# The ~/Code/ path below is up to you
85-
mkdir ~/Code/ansible
86-
touch ~/Code/ansible/hosts
88+
# The ~/Path/To/ path below is up to you
89+
mkdir ~/Path/To/ansible
90+
touch ~/Path/To/ansible/hosts
8791
touch ~/.ansible.cfg
8892

8993
Open that new `~/.ansible.cfg` file and add the following lines:
@@ -92,21 +96,21 @@ Open that new `~/.ansible.cfg` file and add the following lines:
9296
~/.ansible.cfg
9397
: ~~~ ini
9498
[default]
95-
inventory = ~/Code/ansible/hosts
96-
~~~
99+
inventory = ~/Path/To/ansible/hosts
100+
~~~
97101

98102
Add an entry to your new hosts file, pointing to a server that you connected to in the previous section. You can include multiple servers in this file, using either domains or IP addresses, and can even group them. Example:
99103

100104
{: .file-excerpt}
101-
~/Code/ansible/hosts
105+
~/Path/To/ansible/hosts
102106
: ~~~ ini
103107
mainserver.com
104108
myserver.net:2222
105109

106110
[mailservers]
107111
mail1.mainserver.com
108112
mail2.mainserver.com
109-
~~~
113+
~~~
110114

111115
For now, just add one entry, save, and run the following command, very similar to before, to try and ping your server via Ansible.
112116

@@ -117,7 +121,7 @@ You should receive the same output as previously. Note that this time you used `
117121

118122
## Configuration via Playbooks
119123

120-
_Playbooks_ in Ansible define a series of actions to run, and address particular sets of servers. It's important to note that, unlike some other configuration tools, a playbook does not describe a state of the machine, with Ansible determining all the changes that need to be made on its own. However, playbooks should be designed to be idempotent, meaning that they can be run more than once without negative effects. For example, a playbook might have a task that sets up a configuration file for a server and injects a few variables. The playbook should be written such that Ansible can take the template config file, compare it to the actual file, and create/update it only if necessary. Luckily, many Ansible modules take care of the heavy lifting for that.
124+
*Playbooks* in Ansible define a series of actions to run, and address particular sets of servers. It's important to note that, unlike some other configuration tools, a playbook does not describe a state of the machine, with Ansible determining all the changes that need to be made on its own. However, playbooks should be designed to be idempotent, meaning that they can be run more than once without negative effects. For example, a playbook might have a task that sets up a configuration file for a server and injects a few variables. The playbook should be written such that Ansible can take the template configuration file, compare it to the actual file, and create/update it only if necessary. Luckily, many Ansible modules take care of the heavy lifting for that.
121125

122126
You can write playbooks to perform initial server configurations, add users and directories, ensure certain software packages are installed or uninstalled, move files, etc. A playbook can also run a few commands on one set of machines, switch to a different set to run some different commands, and then even switch back to the original or different set of machines. It is procedural, and tasks are run in order, top to bottom.
123127

@@ -132,7 +136,7 @@ Sample Playbook YAML file
132136
tasks:
133137
- [task 1]
134138
- [task 2]
135-
~~~
139+
~~~
136140

137141
For example, the following playbook would log in to all web servers and ensure Apache was started.
138142

@@ -147,15 +151,19 @@ Sample service check playbook
147151
service: name=httpd state=started
148152
become: yes
149153
become_method: sudo
150-
~~~
154+
~~~
151155

152156
You see an example of a task in that playbook:
153157

154-
tasks:
158+
{: .file-excerpt}
159+
Playbook task
160+
: ~~~ yaml
161+
tasks:
155162
- name: Ensure the Apache daemon has started
156163
service: name=httpd state=started
157164
become: yes
158165
become_method: sudo
166+
~~~
159167

160168
Every task should have a name which gets logged and can help you track progress. Following the name line is the module that will be run (in this case, the [service module](http://docs.ansible.com/ansible/service_module.html)), and the other attributes provide more options, in this case instructing Ansible to become the root user.
161169

@@ -165,13 +173,13 @@ Executing a playbook is even easier than running ad-hoc commands like we did ear
165173

166174
ansible-playbook myplaybook.yml
167175

168-
Done! If you want to see what hosts this playbook will affect without having to open up the YAML file, you can run
176+
Done! If you want to see what hosts this playbook will affect without having to open up the YAML file, you can run:
169177

170178
ansible-playbook myplaybook.yml --list-hosts
171179

172180
### Types of Tasks You Can Run
173181

174-
Ansible ships with a large collection of modules that you can run as tasks or via ad-hoc commands. To see a listing of all available modules, run
182+
Ansible ships with a large collection of modules that you can run as tasks or via ad-hoc commands. To see a listing of all available modules, run:
175183

176184
ansible-docs -l
177185

@@ -211,9 +219,9 @@ First, add your new server's IP to your Ansible `hosts` file so that we can addr
211219
: ~~~ ini
212220
[linode]
213221
123.123.123.123
214-
~~~
222+
~~~
215223

216-
Let's write a playbook that creates a new normal user, adds in our public key, and adds the new user to the sudoers file so that we can use such a connection in the future. We're introducing a new aspect of Ansible here: _variables_. See the `vars:` entry and the `NORMAL_USER_NAME` line? You'll notice that it is reused twice in the file so that we only have to change it once.
224+
Let's write a playbook that creates a new normal user, adds in our public key, and adds the new user to the sudoers file so that we can use such a connection in the future. We're introducing a new aspect of Ansible here: *variables*. See the `vars:` entry and the `NORMAL_USER_NAME` line? You'll notice that it is reused twice in the file so that we only have to change it once. Replace `username` with your choosen username.
217225

218226
{: .file}
219227
initialize_basic_user.yml
@@ -222,7 +230,7 @@ initialize_basic_user.yml
222230
- hosts: linode
223231
remote_user: root
224232
vars:
225-
NORMAL_USER_NAME: 'josh'
233+
NORMAL_USER_NAME: 'username'
226234
tasks:
227235
- name: "Create a secondary, non-root user"
228236
user: name={{ NORMAL_USER_NAME }}
@@ -235,7 +243,7 @@ initialize_basic_user.yml
235243
regexp="{{ NORMAL_USER_NAME }} ALL"
236244
line="{{ NORMAL_USER_NAME }} ALL=(ALL) ALL"
237245
state=present
238-
~~~
246+
~~~
239247

240248
Save that file as `initialize_basic_user.yml` and run the playbook with the following command. Note how we specify the use of a particular user (`-u root`) and force Ansible to prompt us for the password (`-ask-pass`) since we don't have key authentication set up yet.
241249

@@ -250,7 +258,7 @@ common_server_setup.yml
250258
: ~~~ yaml
251259
---
252260
- hosts: linode
253-
remote_user: josh
261+
remote_user: username
254262
become: yes
255263
become_method: sudo
256264
vars:
@@ -270,7 +278,7 @@ common_server_setup.yml
270278
with_items: groups['linode']
271279
- name: Update packages
272280
apt: update_cache=yes upgrade=dist
273-
~~~
281+
~~~
274282

275283
Run the command with a few less arguments:
276284

@@ -283,11 +291,11 @@ At any time now you can SSH into the server directly and verify that things are
283291
Finally, let's get a very basic server set up with Apache and PHP, and a test MySQL databases to use. The following playbook downloads the appropriate packages, turns on the Apache and MySQL services, and creates a basic database and user.
284292

285293
{: .file}
286-
common_server_setup.yml
294+
setup_webserver.yml
287295
: ~~~ yaml
288296
---
289297
- hosts: linode
290-
remote_user: josh
298+
remote_user: username
291299
become: yes
292300
become_method: sudo
293301
tasks:
@@ -315,7 +323,7 @@ common_server_setup.yml
315323
mysql_user: name=webapp
316324
password=mypassword
317325
priv=*.*:ALL state=present
318-
~~~
326+
~~~
319327

320328
And as before, run the playbook from your control machine with the following command.
321329

File renamed without changes.

docs/applications/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ modified_by:
77
categories:
88
- remote-desktop
99
- chef
10+
- ansible
1011
- voip
1112
- cloud-storage
1213
- containers

0 commit comments

Comments
 (0)