Chef-Solo is an open source version of chef-client originally developed by Chef Software,Inc.. Chapter 1 , Introduction to Chef and Chef-Solo, explains about Chef, chef-client, and Chef-
Trang 3Solo
Trang 5Installing Chef as a package managerUsing the Omnibus installer
System virtual machines
Process virtual machines
Executing recipes with Vagrant
Provision
Trang 6Data bags
Roles
Restarting services and server handlingSummary
Web UI
Erchef
Message queues
Summary
Trang 7Index
Trang 9Solo
Trang 11dealers and distributors will be held liable for any damages caused or alleged to be causeddirectly or indirectly by this book.
Trang 14Shantanu Zagade
Trang 16Naveed ur Rahman is a self-taught programmer and an avid traveler When he is not
experimenting with the latest in programming and deployment, he is out camping andwatching cricket
BASIC Now, he has experience working for one of the biggest tech names in the MiddleEast
His adventures in programming began at a very young age when he got introduced to GW-Having worked at the largest technology company in the Middle East, Naveed has helpedteams create and deploy applications written in various languages using configurationmanagement tools
I would like to thank my family for supporting me throughout the process of writing Also,the help of Packt Publishing staff has been incredible I would like to thank my projectcoordinator and content development editor who supported me in writing and finalizingthe content Also, the technical reviewers provided me with a clear guideline to make thisbook more effective Moreover, their valuable critiques allowed me to refine my work
Trang 18Anirudh Bhatnagar is a technology consultant with an extensive experience in Agile
product development and consulting He started his career working as a Java developerwith product-based companies such as Adobe Systems, India, where most of his
experience was in Java, J2EE, Spring, Hibernate, XML, Web Services, REST, CMS, SSO,ESB, and Liferay Currently, he is working as a Principal Consultant in Xebia, India withspecialization in Continuous Delivery methodology, and working on developing a PaaSfor service orchestration using Mule ESB, ActiveMQ, Elasticsearch, Jenkins, Maven,Chef, and AWS He has been contributing to the software community through his blogs,articles, projects, meetups, and conferences Recently, he has started a DevOps community
in New Delhi and has spoken at DevOpsDays India 2013
Stuart Ellis works for a Ruby on Rails and mobile software development company, where
he has many hats In his current and previous roles, he has developed software with NETand Ruby, written SQL in a surprising number of dialects, managed different combinations
of Windows and Linux, and studied history
Jorge Moratilla has a Bachelor’s degree in Computer Science and has been working for
Internet companies since 1998 He has been working as a contractor for companies such asSun Microsystems and Oracle, working as a certified instructor and field engineer forseveral years He has a large background working with technologies and products such asLinux, Solaris, LDAP, and Check Point Recently, he has been working in developmentcompanies, mainly as a system administrator, and performing several tasks related withAgile management, testing, and Continuous Deployment As a coordinator of the technicalgroup Madrid DevOps, he promotes the adoption of a culture of continuous improvement
in the enterprise You can meet him at talks and hangouts he organizes in the community
I would like to personally thank my wife Nuria and son Eduardo for being so
understanding and supportive while I was reviewing this book Also, I would like to thank
my dear mom Milagros and dad Toñi, who put in all the effort to give me an education.Finally, I would thank also all those who have contributed to my personal and professionaldevelopment through the years
Trang 20www.PacktPub.com
Trang 21Support files, eBooks, discount offers, and more
You might want to visit www.PacktPub.com for support files and downloads related toyour book
Did you know that Packt offers eBook versions of every book published, with PDF andePub files available? You can upgrade to the eBook version at www.PacktPub.com and as
a print book customer, you are entitled to a discount on the eBook copy Get in touch with
us at < service@packtpub.com > for more details
At www.PacktPub.com, you can also read a collection of free technical articles, sign upfor a range of free newsletters and receive exclusive discounts and offers on Packt booksand eBooks
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt’s online digitalbook library Here, you can access, read and search across Packt’s entire library of books
Trang 22Fully searchable across every book published by PacktCopy and paste, print and bookmark content
On demand and accessible via web browser
Trang 23If you have an account with Packt at www.PacktPub.com, you can use this to accessPacktLib today and view nine entirely free books Simply use your login credentials forimmediate access
Trang 25Chef-Solo is an open source version of chef-client originally developed by Chef Software,Inc It is a complete framework to automate infrastructure operations for building servers
or applications from scratch or adding new configurations to existing systems These
servers are managed by code written in Ruby and it also provides the facility to test andreproduce
The book will take the reader through the workflow of managing one or more servers.Also, it includes many sample recipes to help you get started
Throughout the process, we will have a look at the different interaction points and you willlearn how Chef-Solo helps to minimize your efforts to build and efficiently manage
Trang 26Chapter 1
, Introduction to Chef and Chef-Solo, explains about Chef, chef-client, and Chef-Solo It explains about the core concepts in Chef and the terminologies with some usecases
Chapter 2, Setting Up an Environment for Chef-Solo, guides you to install Chef-Solo on
your Ubuntu machine, and discusses cookbooks and their structure in detail It also
provides step-by-step instructions on how to run cookbooks using Chef-Solo with customconfigurations
Chapter 3, Setting Up a Development Environment, explains virtual machines and their
providers In this chapter, we will set up the development environment using Vagrant andexecute some sample recipes
Chapter 4, Developing Cookbooks, looks deeper into developing recipes and how to
manage the recipes in cookbooks It also provides more detailed information on metadata,attributes, templates, files, resources, and data bags Also, it includes some tools to
manage and create cookbooks, for example, Knife and Berkshelf
Chapter 5, More about Cookbooks and Recipes, continues with the last chapter’s
cookbooks and manages the remaining contents with files and templates This chapterincludes Python/Django cookbooks and information about upstream service
Chapter 6, Chef-Solo and Docker, covers the installation of Docker and creation of Docker
images using Chef-Solo Also, this chapter includes some recommendations on how towork on recipes of ongoing projects and keep them aligned with Chef-Solo
Trang 28You need only a single Ubuntu machine to get started This book contains a step-by-stepguide to set up a development environment Once you have successfully installed
everything, you can easily reproduce the same on multiple machines
Trang 30This book is for system administrators and system engineers who have an understanding
of configuration management tools and infrastructure It helps you to understand the needfor these tools and provides you with a step-by-step guide to maintain your existing
infrastructure It also contains the most frequently used application recipes to get startedimmediately
Trang 32In this book, you will find a number of styles of text that distinguish between differentkinds of information Here are some examples of these styles, and an explanation of theirmeaning
Trang 34Feedback from our readers is always welcome Let us know what you think about thisbook—what you liked or may have disliked Reader feedback is important for us todevelop titles that you really get the most out of
To send us general feedback, simply send an e-mail to < feedback@packtpub.com >, andmention the book title via the subject of your message
If there is a topic that you have expertise in and you are interested in either writing orcontributing to a book, see our author guide on www.packtpub.com/authors
Trang 36Now that you are the proud owner of a Packt book, we have a number of things to helpyou to get the most from your purchase
Trang 37You can download the example code files for all Packt books you have purchased fromyour account at http://www.packtpub.com If you purchased this book elsewhere, you canvisit http://www.packtpub.com/support and register to have the files e-mailed directly toyou
Trang 38Although we have taken every care to ensure the accuracy of our content, mistakes dohappen If you find a mistake in one of our books—maybe a mistake in the text or thecode—we would be grateful if you would report this to us By doing so, you can saveother readers from frustration and help us improve subsequent versions of this book Ifyou find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the
details of your errata Once your errata are verified, your submission will be accepted andthe errata will be uploaded on our website, or added to any list of existing errata, under theErrata section of that title Any existing errata can be viewed by selecting your title from
http://www.packtpub.com/support
Trang 39Piracy of copyright material on the Internet is an ongoing problem across all media AtPackt, we take the protection of our copyright and licenses very seriously If you comeacross any illegal copies of our works, in any form, on the Internet, please provide us withthe location address or website name immediately so that we can pursue a remedy
Please contact us at < copyright@packtpub.com > with a link to the suspected pirated
material
We appreciate your help in protecting our authors, and our ability to bring you valuablecontent
Trang 40You can contact us at < questions@packtpub.com > if you are having a problem with anyaspect of the book, and we will do our best to address it
Trang 42Solo
Chapter 1 Introduction to Chef and Chef-Chef is a configuration management system to automate the process of deploying servers
to any physical, virtual, or cloud location Each setup involves the basic structure with oneChef server and different nodes managed by the chef-client Chef infrastructure is
managed by Ruby code and it allows you to test, build, and replicate your infrastructure.This chapter will guide you through the basics of Chef and how it can help you in building
Trang 43Chef is a complete framework to automate infrastructure operations to build servers orapplications from scratch or add new configurations to existing systems Servers are
For instance, if you want 100 servers with Python/Django running Nginx with uWSGI andyou want to have the same installations on each node, Chef can make this happen in
minutes; it also provides you with the switch to turn your nodes on and off It can checkfor revision control system and is responsible for pulling recent updates from the
repository You can easily revert the system to the previous state if something does nothappen according to your needs With Chef, system administrators can spend less time onmaintenance and more time on innovation
Traditional infrastructure is slow and tedious; it involves many steps to build servers andrunning applications All your configurations are in one place and you will not worryabout the several configurations of different servers While scaling your application, it ishighly recommended to use Chef, as you can easily split your app on to different servers
by using roles and nodes You do not have to install the same application 10 times on onemachine or any other, just create a new node in Chef server and in a few minutes, theserver will be ready to handle the application Also, there is no need to maintain the
documentation of servers, as the recipes’ code is self-explanatory and easy to grasp for anew user
Chef is developed by Chef Software, Inc and recently they released Version 11.0 Chefcode is completely rewritten in Version 11.0, swapping out Apache CouchDB for
PostgreSQL and Ruby for Erlang The result is massive and now a single Chef server canhandle more than 1000 nodes (clients)
Chef is provided in the following three versions:
Private Chef: This is an enterprise version that supports multi-tenancy to provide a
highly scalable server to handle several nodes It should be located in the client’spremises and managed behind a firewall
Hosted Chef: This is an SAAS service managed by Chef Software, Inc It is a cloud-based service and highly available (24/7 x 365), with roles and resource-based accesscontrols It does not require a firewall
Open source Chef: This is a community-driven version with almost identical
Trang 44updates, defining roles, data migrations, and ensuring that the infrastructure scalesappropriately
approach ensures that each node has persistent data and files
Knife: Knife is a tool that provides an interface between local-repo and the server It
is used to retrieve cookbooks, policies, roles, environments, and other items
Trang 46Chef-Solo is an open source version of chef-client It executes recipes from the local
cookbooks It is a limited version of chef-client and has much fewer features than it Itdoes not have the following features:
Similarly, you can search by instance type, node, environment, nested attributes, andmultiple arguments
Centralized distribution of cookbooks: As Chef-Solo works individually, it does
not have the ability for distribution of cookbooks Even if you have deployed Chefserver, Chef-Solo will not be able to retrieve recipes from a centralized source
Centralized API for integration with other infrastructure components: There is
no centralized API for Chef-Solo to retrieve other configurations from a differentmachine For instance, if your application needs database connectivity, you will not
be able to get the IP of the database source There are multiple solutions to addressthis problem, which we will discuss in the upcoming chapters
Authentication: Chef-Solo has no authentication module; anyone can execute the
recipes:
# chef-solo privileges
test ALL=(ALL) NOPASSWD: /usr/bin/chef-solo
Trang 47Persistent attributes: There is no centralized cookbook system for Chef-Solo; it just
executes the recipes from a local cookbook
Although Chef-Solo has fewer features, it provides the core use of developing cookbooks.Moreover, Chef-Solo provides a simple way to start You can build the system by usingcookbooks and it’s extremely useful for booting new machines
Like chef-client, Chef-Solo can be used for servers, applications, or any physical machine
Trang 49We will now discuss some terminologies about Chef As we have already discussed, Chefhas two different types, namely Chef server and Chef-Solo Chef-Solo provides a simpleway to start The following terminologies mentioned are used for Chef server as well asChef-Solo