- Ansible 2 Cloud Automation Cookbook
- Aditya Patawari Vikas Aggarwal
- 476字
- 2021-06-24 18:43:34
Introduction of Ansible entities
Before we start diving into the Ansible world, we need to know some basics:
- Inventory: We need to have a list of hosts that we want to manage. Inventory is that list. In its simplest form, this can be a text file created manually which just lists the IP addresses of the servers. This is usually enough for small infrastructure or if the infrastructure is static in nature. It follows ini syntax and a typical inventory would look like this:
[webservers]
server1
[application]
server1
server2
If our infrastructure is dynamic, where we add and remove servers frequently, we can use dynamic inventory. This would allow us to generate the inventory in real time. Ansible provides dynamic inventory scripts for many cloud providers and allows us to create dynamic inventory scripts as per our need for non-standard setups. We will use dynamic inventory in this book since it is better suited to cloud based environments.
- Modules: Ansible modules are executable plugins that get the real job done. Ansible comes with thousands of modules which can do tasks from installing packages to creating a server. Most of the modules accept parameters based upon which they take suitable actions to move the server towards a desired state. While this book uses modules primarily in the YAML code, it is possible to use modules in command line as an argument to Ansible ad hoc command.
- Tasks: A task is a call to an Ansible module along with all the requirements like parameters, variables etc. For example, a task may call upon the template module to read a Jinja template and set of variables, and generate the desired state of a file for the remote server.
- Roles: Ansible roles describe the particular role that a server is going to play. It consists of YAML code which defines tasks. It also consists of the dependencies for the execution of tasks like required files, templates and variables.
- Playbooks: A playbook is a YAML file where we associate roles and hosts. It is possible to write the tasks in the playbook itself and not use roles but we would strongly discourage this practice. For the sake of readability and better code management, we suggest that playbooks should be kept small with just the name of the hosts or groups to target as defined in inventory and calls to the roles.
- Variables: Just like any other programming language, Ansible also has good old-fashioned variables. They hold values which can be used in tasks and templates to perform certain actions. Variables can be created before execution in a file or generated and modified during runtime. A very common use case is to invoke certain tasks if a variable holds a certain value or to store the output of a task in a variable and use it in one of the subsequent tasks.
推薦閱讀
- 虛擬儀器設計測控應用典型實例
- Google Cloud Platform Cookbook
- Managing Mission:Critical Domains and DNS
- 精通Excel VBA
- Splunk Operational Intelligence Cookbook
- Kubernetes for Developers
- The Python Workshop
- Python:Data Analytics and Visualization
- 悟透AutoCAD 2009案例自學手冊
- 空間機器人
- Learn Microsoft Azure
- PostgreSQL 10 High Performance
- 中文版Photoshop情境實訓教程
- 我的IT世界
- iLike職場大學生就業指導:C和C++方向