Skip to content

Commit 7a951b3

Browse files
Merge pull request #2286 from andystevensname/rc-v0.5
RC v0.5
2 parents a747b85 + 799ddcb commit 7a951b3

File tree

174 files changed

+3630
-1139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+3630
-1139
lines changed

ci/vale/dictionary.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ antispam
2727
ap
2828
apache2
2929
api
30+
apiserver
3031
appimage
3132
appletalk
3233
appserver
@@ -177,12 +178,14 @@ configtest
177178
configurability
178179
containerised
179180
convolutional
181+
cookstyle
180182
coose
181183
copyfrom
182184
copyto
183185
coreutils
184186
corporateclean
185187
cpanminus
188+
cpu
186189
cqlsh
187190
cqlshrc
188191
craftbukkit
@@ -215,6 +218,7 @@ daemonizes
215218
daemonizing
216219
daemonset
217220
dahdi
221+
databags
218222
datacenter
219223
datadir
220224
dataset
@@ -384,6 +388,7 @@ flamegraph
384388
flamegraphs
385389
flatpress
386390
flyspray
391+
foodcritic
387392
fortran
388393
fpm
389394
fragging
@@ -703,6 +708,7 @@ luminus
703708
lxml
704709
lzma
705710
lzopio
711+
macos
706712
magento
707713
maildir
708714
maildirs
@@ -744,6 +750,7 @@ mesos
744750
metabase
745751
metacity
746752
metapackage
753+
metaparameters
747754
metricbeat
748755
microblogs
749756
microservice
@@ -1006,6 +1013,7 @@ pty
10061013
pubkey
10071014
publickey
10081015
puppetd
1016+
puppetlabs
10091017
puppetmaster
10101018
puttygen
10111019
pv

docs/applications/configuration-management/automatically-configure-servers-with-ansible-and-playbooks/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ This section demonstrates using a playbook to automate basic server configuratio
279279

280280
### Install the Stack
281281

282-
Create a basic server setup with Apache, PHP, and a test MySQL database to use.
282+
Create a basic server setup with NGINX, PHP, and a test MySQL database to use.
283283

284-
1. The following playbook downloads the appropriate packages, turns on the Apache and MySQL services, and creates a basic database and user:
284+
1. The following playbook downloads the appropriate packages, turns on the nginx and MySQL services, and creates a basic database and user:
285285

286286
{{< file "setup_webserver.yml" yaml >}}
287287
---

docs/applications/configuration-management/beginners-guide-chef/index.md

Lines changed: 72 additions & 32 deletions
Large diffs are not rendered by default.

docs/applications/configuration-management/creating-your-first-chef-cookbook/index.md

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,46 @@ author:
33
name: Elle Krout
44
55
description: 'Learn how to create Chef cookbooks by creating a LAMP stack in Chef'
6-
keywords: ["chef", "automation", "cookbooks", "opscode", "lamp", "lamp stack", "beginner", "server automation"]
6+
keywords: ["chef", "automation", "cookbooks", "configuration management", "DevOps"]
77
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
88
aliases: ['applications/chef/creating-your-first-chef-cookbook/']
9-
modified: 2018-08-06
9+
modified: 2019-01-17
1010
modified_by:
1111
name: Linode
1212
published: 2015-06-10
1313
title: Creating Your First Chef Cookbook
1414
external_resources:
1515
- '[Chef](http://www.chef.io)'
16+
- '[About Cookbooks](https://docs.chef.io/cookbooks.html)'
17+
- '[About Knife](https://docs.chef.io/knife.html)'
18+
- '[About Nodes](https://docs.chef.io/nodes.html)'
1619
---
1720

18-
Cookbooks are one of the key components in Chef. They describe the *desired state* of your nodes, and allow Chef to push out the changes needed to achieve this state. Creating a cookbook can seem like an arduous task at first, given the sheer number of options provided and areas to configure, so in this guide we will walk through the creation of one of the first things people often learn to configure: A LAMP stack.
21+
Chef cookbooks describe the *desired state* of your nodes, and allow Chef to push out the changes needed to achieve this state. In this guide you will learn how to create a cookbook that configures A LAMP stack on a Linode.
1922

2023
![Creating Your First Chef Cookbook](creating-your-first-chef-cookbook.png "Creating Your First Chef Cookbook")
2124

22-
Prior to using this guide, set up Chef with the [Setting Up a Chef Server, Workstation, and Node](/docs/applications/configuration-management/install-a-chef-server-workstation-on-ubuntu-18-04/) guide. When following that guide, **choose Ubuntu 16.04 as your Linux image for the Chef node**. This is required because the [MySQL Chef cookbook](https://supermarket.chef.io/cookbooks/mysql/) that will be used is not yet compatible with Ubuntu 18.04.
25+
## Before You Begin
2326

24-
If needed, review the [Beginner's Guide to Chef](/docs/applications/configuration-management/beginners-guide-chef/).
27+
1. Set up Chef with the [Setting Up a Chef Server, Workstation, and Node](/docs/applications/configuration-management/install-a-chef-server-workstation-on-ubuntu-18-04/) guide. When following that guide, **choose Ubuntu 16.04 as your Linux image for the Chef node you will bootstrap and manage**. This guide will use the [MySQL Chef cookbook](https://supermarket.chef.io/cookbooks/mysql/), which does not yet support Ubuntu 18.04.
2528

26-
The examples in this tutorial require a root user account. Readers who choose to use a limited user account will need to prefix commands with sudo where required when working on the Chef client node. If you have yet to create a limited user account, follow the steps in the [Securing Your Server](/docs/security/securing-your-server/#add-a-limited-user-account) guide.
29+
1. Once your node is bootstrapped, you can use a Chef cookbook to secure your node. Consider using the [Users](https://supermarket.chef.io/cookbooks/users) cookbook and the [Firewall](https://supermarket.chef.io/cookbooks/firewall) cookbook for this work. While this is not required to complete this guide, it is recommended.
30+
31+
1. You can also review [A Beginner's Guide to Chef](/docs/applications/configuration-management/beginners-guide-chef/)to receive an overview on Chef concepts.
32+
33+
1. The examples in this tutorial require a user account with sudo privileges. Readers who use a limited user account will need to prefix commands with sudo when issuing commands to the Chef client node and replace `-x root` with `-x username` where `username` is your limited user account.
34+
35+
1. Ensure that your workstation's `/etc/hosts` file contains its own IP address and hostname and the IP address and hostname for any nodes you will interact with from the workstation. For example:
36+
37+
{{< file "/etc/hosts">}}
38+
127.0.0.1 localhost
39+
192.0.2.0 workstation
40+
198.51.100.0 node-hostname
41+
{{</ file >}}
2742

2843
## Create the Cookbook
2944

30-
1. From your workstation, move to your `cookbooks` directory in `chef-repo`:
45+
1. From your workstation, move to your `chef-repo/cookbooks` directory:
3146

3247
cd chef-repo/cookbooks
3348

@@ -39,27 +54,25 @@ The examples in this tutorial require a root user account. Readers who choose to
3954

4055
cd lamp_stack
4156

42-
1. List the files located in the newly-created cookbook to see that a number of directories and files have been created:
43-
44-
ls
57+
If you issue the `ls` command, you should see the following files and directories:
4558

46-
{{< output >}}
47-
Berksfile CHANGELOG.md chefignore LICENSE metadata.rb README.md recipes spec test
48-
{{</ output >}}
59+
{{< output >}}
60+
Berksfile CHANGELOG.md chefignore LICENSE metadata.rb README.md recipes spec test
61+
{{</ output >}}
4962

50-
For more information about these directories see the [Beginner's Guide to Chef](/docs/applications/configuration-management/beginners-guide-chef/).
63+
### default.rb
5164

52-
## default.rb
65+
Attributes are pieces of data that help the chef-client determine the current state of a node and any changes that have taken place on the node from one chef-client run to another. Attributes are gathered from the state of the node, cookbooks, roles and environments. Using these sources, an attribute list is created for each chef-client run and is applied to the node. If a `default.rb` file exists within a cookbook, it will be loaded first, but has the lowest attribute precedence.
5366

5467
The `default.rb` file in `recipes` contains the "default" recipe resources.
5568

56-
Because each section of the LAMP stack (Apache, MySQL, and PHP) will have its own recipe, the `default.rb` file is used to prepare your servers.
69+
In this example, the `lamp_stack` cookbook's `default.rb` file is used to update the node's distribution software.
5770

58-
1. From within your `lamp_stack` directory, navigate to the `recipes` folder:
71+
1. From within the `lamp_stack` directory, navigate to the `recipes` folder:
5972

6073
cd recipes
6174

62-
1. Open `default.rb` and add the Ruby command below, which will run system updates:
75+
1. Open the `default.rb` file and add the following code:
6376

6477
{{< file "~/chef-repo/cookbooks/lamp_stack/recipe/default.rb" ruby >}}
6578
#
@@ -83,21 +96,25 @@ end
8396

8497
knife cookbook upload lamp_stack
8598

86-
1. Test that the recipe has been added to the chef server:
99+
1. Verify that the recipe has been added to the Chef server:
87100

88101
knife cookbook list
89102

103+
You should see a similar output:
104+
105+
{{< output >}}
106+
lamp_stack 0.1.0
107+
{{</ output >}}
108+
90109
1. Add the recipe to your chosen node's *run list*, replacing `nodename` with your node's name:
91110

92111
knife node run_list add nodename "recipe[lamp_stack]"
93112

94-
Because this is the default recipe, the recipe name does not need to be defined after `lamp_stack` cookbook in the code above.
95-
96-
1. Access your chosen node and run the *chef-client*:
113+
1. From your workstation, apply the configurations defined in the cookbook by running the chef-client on your node. Replace `nodename` with the name of your node:
97114

98-
chef-client
115+
knife ssh 'name:nodename' 'sudo chef-client' -x root
99116

100-
It should output a successful Chef run. If not, review your code for any errors, usually defined in the output of the `chef-client` run.
117+
Your output should display a successful Chef run. If not, review your code for any errors, usually defined in the output of the `chef-client` run.
101118

102119
## Apache
103120

@@ -139,20 +156,26 @@ end
139156

140157
Because this is not the `default.rb` recipe, the recipe name, *apache*, must be appended to the recipe value.
141158

142-
1. From that **node**, run `chef-client`:
159+
{{< note >}}
160+
To view a list of all nodes managed by your, Chef server issue the following command from your workstation:
161+
162+
knife node list
163+
{{</ note >}}
164+
165+
1. From your workstation, apply the configurations defined in the cookbook by running the chef-client on your node. Replace `nodename` with the name of your node:
143166

144-
chef-client
167+
knife ssh 'name:nodename' 'sudo chef-client' -x root
145168

146169
If the recipe fails due to a syntax error, Chef will note it during the output.
147170

148171
1. After a successful `chef-client` run, check to see if Apache is running:
149172

150-
systemctl status apache2
151-
152-
It should say that `apache2` is running.
173+
knife ssh 'name:nodename' 'systemctl status apache2' -x root
153174

154175
{{< note >}}
155-
Repeat Steps 5-7 to upload the cookbook and run chef-client as needed through the rest of this guide to ensure your recipes are working properly and contain no errors. Remember to replace the recipe name in the run list code when adding a new recipe.
176+
Repeat steps 4-7 to upload each recipe to your Chef server, as you create it. Run `chef-client` on your node, as needed, throughout the rest of this guide to ensure your recipes are working properly and contain no errors. When adding a new recipe, ensure you are using its correct name in the run list.
177+
178+
This is not the recommended workflow for a production environment. You might consider creating different [Chef environments](https://docs.chef.io/environments.html) for testing, staging, and production.
156179
{{< /note >}}
157180

158181
### Configure Virtual Hosts
@@ -163,7 +186,7 @@ This configuration is based off of the [How to Install a LAMP Stack on Ubuntu 16
163186

164187
chef generate attribute ~/chef-repo/cookbooks/lamp_stack default
165188

166-
1. Within the new `default.rb`, create the default values of the cookbook:
189+
1. Within the new `default.rb`, create the default values for the cookbook:
167190

168191
{{< file "~/chef-repo/cookbooks/lamp_stack/attributes/default.rb" ruby >}}
169192
default["lamp_stack"]["sites"]["example.com"] = { "port" => 80, "servername" => "example.com", "serveradmin" => "[email protected]" }
@@ -210,7 +233,7 @@ node["lamp_stack"]["sites"].each do |sitename, data|
210233
end
211234
{{< /file >}}
212235

213-
1. However, this does not create the directory itself. To do so, the `directory` resource should be used, with a `true` recursive value so all directories leading up to the `sitename` will be created. A permissions value of `0755` allows for the file owner to have full access to the directory, while group and regular users will have read and execute privileges:
236+
1. Create the `document_root` directory. Declare a `directory` resource with a `true` recursive value so all directories leading up to the `sitename` will be created. A permissions value of `0755` allows for the file owner to have full access to the directory, while group and regular users will have read and execute privileges:
214237

215238
{{< file "~/chef-repo/cookbooks/lamp_stack/apache.rb" ruby >}}
216239
node["lamp_stack"]["sites"].each do |sitename, data|
@@ -275,7 +298,7 @@ end
275298

276299
The name of the template resource should be the location where the virtual host file is placed on the nodes. The `source` is the name of the template file. Mode `0644` gives the file owner read and write privileges, and everyone else read privileges. The values defined in the `variables` section are taken from the attributes file, and they are the same values that are called upon in the template.
277300

278-
1. The sites now need to be enabled in Apache, and the server restarted. This should *only* occur if there are changes to the virtual hosts, so the `notifies` value should be added to the `template` resource. `notifies` tells Chef when things have changed, and **only then** runs the commands:
301+
1. The sites need to be enabled in Apache, and the server restarted. This should *only* occur if there are changes to the virtual hosts, so the `notifies` value should be added to the `template` resource. `notifies` tells Chef when things have changed, and **only then** runs the commands:
279302

280303
{{< file "~/chef-repo/cookbooks/lamp_stack/recipes/apache.rb" ruby >}}
281304
template "/etc/apache2/sites-available/#{sitename}.conf" do
@@ -294,7 +317,7 @@ end
294317

295318
The `notifies` command names the `:action` to be committed, then the resource, and resource name in square brackets.
296319

297-
1. `notifies` can also call on `execute` commands, which will run `a2ensite`and enable the sites we've made virtual hosts files for. Add the following `execute` command **above** the `template` resource code to create the `a2ensite` script:
320+
1. `notifies` can also call on `execute` commands, which will run `a2ensite`and enable the sites that have corresponding virtual hosts files. Add the following `execute` command **above** the `template` resource code to create the `a2ensite` script:
298321

299322
{{< file "~/chef-repo/cookbooks/lamp_stack/recipes/apache.rb" ruby >}}
300323
# [...]
@@ -458,7 +481,7 @@ Chef contains a feature known as *data bags*. Data bags store information, and c
458481
knife data bag create mysql rtpass.json --secret-file ~/chef-repo/.chef/encrypted_data_bag_secret
459482

460483
{{< note >}}
461-
Some knife commands require that information be edited as JSON data using a text editor. Your `knife.rb` file should contain a configuration for the text editor to use for such commands. If your `knife.rb` file does not already contain this configuration, add `knife[:editor] = "/usr/bin/vim"` to the bottom of the file to set vim as the default text editor.
484+
Some knife commands require that information be edited as JSON data using a text editor. Your `config.rb` file should contain a configuration for the text editor to use for such commands. If your `config.rb` file does not already contain this configuration, add `knife[:editor] = "/usr/bin/vim"` to the bottom of the file to set vim as the default text editor.
462485
{{</ note >}}
463486

464487
You will be asked to edit the `rtpass.json` file:
@@ -527,12 +550,6 @@ end
527550

528551
`mysqldefault` is the name of the MySQL service for this container. The `inital_root_password` calls to the value defined in the text above, while the action creates the database and starts the MySQL service.
529552

530-
{{< note >}}
531-
When running MySQL from your nodes you will need to define the socket:
532-
533-
mysql -S /var/run/mysql-mysqldefault/mysqld.sock -p
534-
{{< /note >}}
535-
536553
## PHP
537554

538555
1. Under the recipes directory, create a new `php.rb` file. The commands below install PHP and all the required packages for working with Apache and MySQL:
@@ -599,4 +616,4 @@ end
599616
knife cookbook upload lamp_stack
600617
knife node run_list add nodename "recipe[lamp_stack],recipe[lamp_stack::apache],recipe[lamp_stack::mysql],recipe[lamp_stack::php]"
601618

602-
You have just created a LAMP Stack cookbook. Through this guide, you should have learned to use the execute, package, service, node, directory, template, cookbook_file, and mysql_service resources within a recipe, as well as download and use LWRPs, create encrypted data bags, upload/update your cookbooks to the server, and use attributes, templates, and cookbook files, giving you a strong basis in Chef and cookbook creation for future projects.
619+
You have just created a LAMP Stack cookbook. Through this guide, you should have learned to use the execute, package, service, node, directory, template, cookbook_file, and mysql_service resources within a recipe, as well as download and use LWRPs, create encrypted data bags, upload/update your cookbooks to the server, and use attributes, templates, and cookbook files. This gives you a strong basis in Chef and cookbook creation for future projects.

0 commit comments

Comments
 (0)