Buch, Englisch, 474 Seiten, Format (B × H): 178 mm x 254 mm
The Practical Guide for Administrators and DevOps Teams
Buch, Englisch, 474 Seiten, Format (B × H): 178 mm x 254 mm
ISBN: 978-1-4932-2702-0
Verlag: Rheinwerk Verlag GmbH
If you want to keep your servers in order, Ansible is the tool of choice! In this practical guide, you’ll learn how to use Ansible to automate server configuration, software deployment, and more. Start by installing Ansible and setting up your initial inventory management process. Then, follow step-by-step instructions for system orchestration, from the basics of playbooks and tasks to using Ansible with Docker. With expert tips and best practices for testing, debugging, and more, this is your all-in-one guide to automating with Ansible!
Highlights include:
1) Basic setup
2) Inventory management
3) Ad-hoc commands and patterns
4) YAML
5) Playbooks, tasks, and plays
6) Modularization
7) Roles
8) Includes
9) Module library
10) Web interfaces
11) Docker
12) Custom collections and modules
Autoren/Hrsg.
Fachgebiete
Weitere Infos & Material
. Preface. 21
. About This Book. 23
. Formatting. 23
. Ansible Versions. 25
. Platforms and Linux Distributions. 25
1. Introduction and Installation. 27
1.1. What Is Ansible?. 27
1.2. What Is Ansible Not?. 29
1.3. History and Versions. 30
1.4. Setup/Lab Environment. 31
1.5. Ansible Installation on the Control Host. 36
1.6. Installation via PIP (plus virtualenv). 38
1.7. Authentication and Authorization on Target Hosts. 39
1.8. Setting Up SSH Public Key Authentication. 41
1.9. An Ad Hoc Test without Any Configuration. 42
1.10. Another Note on Migrating from Older Versions. 43
2. Basic Setup and Initial Inventory Management. 45
2.1. Setting Up the Directory Structure. 45
2.2. Basic Configuration (ansible.cfg). 46
2.3. Creating and Managing a Static Inventory. 48
2.4. Configuration Settings versus Parameters versus …?. 50
2.5. Inventory Aliases and Namespaces. 51
2.6. Beyond Ping. 53
2.7. A Somewhat More Complex Example. 55
2.8. Alternative or Multiple Inventories. 56
3. Ad Hoc Commands and Patterns. 59
3.1. Ad Hoc Commands. 59
3.2. Use Cases Beyond “command” and “shell”. 61
3.3. Idempotency. 61
3.4. Internal Workings. 63
3.5. The Ansible Console. 66
3.6. Patterns for Addressing Hosts. 67
4. YAML: The Configuration and Serialization Language. 69
4.1. Syntax and Structure. 69
4.2. Editing YAML Files. 70
4.3. Syntactic Checks. 72
4.4. Lists and Maps. 73
4.5. Nested Structures. 73
4.6. Text Passages and Block Expressions. 75
4.7. Nothingness in YAML. 76
4.8. Anchors and References. 77
5. Playbooks and Tasks: The Basics. 79
5.1. Hello Ansible: The Very First Playbook. 79
5.2. Formulation of Tasks. 83
5.3. Ending Plays. 85
5.4. The Problematic Colon. 85
5.5. Error Handling and Retrying Files. 86
5.6. Tags. 88
5.7. The “ansible-playbook” Command. 90
5.8. An Example of an Apache Installation. 91
5.9. Handler: Executing Tasks Only on Changes. 95
6. Playbooks and Tasks: Advanced Methods. 103
6.1. Variables. 103
6.2. Registered Variables. 112
6.3. Facts and Implicit Variables. 115
6.4. Conditional Execution with “when”. 121
6.5. Handling System Differences: What’s the Deal Now?. 122
6.6. Jinja and Templates. 131
6.7. Variable Tests. 141
6.8. Lookup Plug-ins. 143
6.9. Loops. 145
6.10. Error Handling with “failed_when” and “ignore_errors”. 158
6.11. Blocks. 159
6.12. Timeouts and Asynchronous Execution. 161
6.13. Local Tasks. 163
6.14. Environment Variables. 166
7. Using Modules and Collections. 169
7.1. Collections. 169
7.2. Module. 173
7.3. Modules for Command Execution. 174
7.4. Modules for Package Management. 175
7.5. Modules for Managing Files and File Contents. 177
7.6. Modules for Other Typical Administrative Tasks. 182
7.7. Modules for Interacting with Network Services. 185
7.8. Special Modules (Control Flow Management, Etc.). 186
8. Modularization with Roles and Includes. 191
8.1. Creating and Using Roles. 191
8.2. The Online Ansible Galaxy Repository. 198
8.3. Using Imports and Includes. 198
8.4. Apache Once Again. 202
8.5. Documentation (and Conventions). 206
8.6. Reusing Roles. 209
9. Web Interfaces: AWX and More. 213
9.1. Installation of Python Packages on Current Debian and Ubuntu Systems. 213
9.2. Ansible Configuration Management Database (“ansible-cmdb”). 214
9.3. Preparations for Operating More Demanding Applications. 216
9.4. The Gitea Git Server. 219
9.5. AWX. 223
9.6. ARA. 229
9.7. Other Applications Not Considered in Detail Here. 230
9.8. Terminating or Deleting Applications That Are No Longer Needed. 233
10. Additional Tools and Techniques. 235
10.1. Ansible Vault. 235
10.2. Debugging and Troubleshooting. 244
10.3. Accelerating Playbooks with Pipelining. 257
10.4. The Talking Cow. 258
10.5. Ansible in Pull Mode. 259
11. Ansible and Docker. 265
11.1. Installing Docker. 265
11.2. Docker Modules. 267
11.3. An Example Application. 274
11.4. Ansible and Docker Compose. 278
11.5. The “docker” Connection Plug-in. 282
11.6. Creating Images. 283
12. Inventory Management: Advanced Methods. 289
12.1. The “ansible-inventory” Command. 289
12.2. Nested Groups. 290
12.3. Static Inventories in YAML format. 291
12.4. Creating on-the-Fly Inventories with “add_host”. 293
12.5. Dynamic Groups with “group_by”. 295
12.6. Dynamic and External Inventories. 298
13. Ansible and the Cloud. 303
13.1. Version Issues and virtualenv. 304
13.2. Where to Store Keys, Tokens, Secrets, Etc. 304
13.3. Hetzner Cloud. 305
13.4. Amazon Web Services Elastic Compute Cloud. 311
13.5. Proxmox Virtual Environment. 318
14. Ansible as an Orchestration Tool. 325
14.1. Many Target Hosts for Testing. 325
14.2. Altering the Sequence of Execution. 326
14.3. Delegation. 335
15. Ansible and Windows. 339
15.1. A Control Host Based on Windows. 339
15.2. Windows Targets and Windows Remote Management. 343
15.3. Preparations on the Control Host. 343
15.4. Prerequisites on the Windows Side and Windows Remote Management Setup. 344
15.5. Windows Remote Management Troubleshooting. 345
15.6. Setup with an Active Directory and Kerberos. 346
15.7. Windows Modules. 348
16. Callback Plug-ins. 351
16.1. Stdout Callback Plug-ins. 351
16.2. Aggregate and Notification Callback Plug-ins. 353
17. Creating Your Own Collections and Modules. 355
17.1. Namespaces, Names, and Setting Up a Collection Project. 355
17.2. Playbooks in Collections. 357
17.3. Roles in Collections. 358
17.4. Modules in Collections. 359
17.5. Plug-ins in Collections. 371
17.6. Deploying and Installing Collections. 373
18. Developing and Testing with Molecule. 377
18.1. Preparations and Setup. 377
18.2. Getting Started. 379
18.3. Develop. 380
18.4. Testing with the Ansible Verifier. 383
18.5. Testing with the Testinfra Verifier. 385
18.6. The Complete Test Cycle. 386
18.7. Outlook and Conclusion. 387
19. Recipes, How-Tos, and Best Practices. 389
19.1. New Projects. 389
19.2. Administration. 391
19.3. Jinja Magic. 401
19.4. Tasks and Control Flow. 408
19.5. Miscellaneous. 415
20. What Could Be Better, and What Is Still Missing?. 421
20.1. Tracking Long-Running Tasks. 421
20.2. Finishing the Processing of a Role. 422
20.3. Loops over Blocks. 424
20.4. Locking with Concurrent Playbook Calls. 425
20.5. Conclusion. 426
. Appendices. 427
A. Project-Specific Environment Variables with “direnv”. 429
B. The “pass” Password Manager. 433
C. Secure Shell. 437
D. Regular Expressions. 455
E. “vim” and “nano” Tips and Tricks. 463
. The Author. 467
. Index. 469