- Learning DevOps
- Mikael Krief
- 376字
- 2021-06-24 12:32:12
Writing a basic playbook
The code of a playbook is written in YAML, a declarative language that allows us to easily visualize the configuration steps.
To understand what a playbook looks like, let's look at a simple and classic example that is the installation of an nginx server on an Ubuntu VM. Previously, we created a working devopsansible directory, inside which we will create a playbook.yml file and insert the following content code:
---
- hosts: all
tasks:
- name: install and check nginx latest version
apt: name=nginx state=latest
- name: start nginx
service:
name: nginx
state: started
---
Let's take a look at this in detail:
- First of all, the YAML file starts and ends with the optional --- characters.
- The - hosts property contains the list of hosts to configure. Here, we have written the value to this property as all to install nginx on all of the VMs listed in our inventory. If we want to install it only on a particular group, for example, on the webserver group, we will note it as follows:
---
- hosts: webserver
- Then, we indicate the list of tasks or actions to be performed on these VMs, with the property of the list of tasks.
- Under the tasks element, we describe the list of tasks and, for each of them, a name that serves as a label, in the name property. Under the name, we call the function to be executed using the Ansible modules and their properties. Here, in our example, we have used two modules:
- apt: This allows us to retrieve a package (the apt-get command) to get the latest version of the nginx package.
- service: This allows us to start or stop a service—in this example, to start the nginx service.
What we notice is that it does not require any knowledge of development or IT scripting to use Ansible; the important thing is to know the list of actions to perform on VMs to configure them. The Ansible playbook is, therefore, a sequence of actions that are encoded in Ansible modules.
We have just seen that the tasks used in playbooks use modules, so I now propose a brief overview of the modules and their use.
- 郎景和院士“關(guān)愛女性健康”系列:婦科腫瘤的故事
- 同仁眼超聲診斷手冊(cè)
- 2021中國(guó)腫瘤登記年報(bào)(漢英)
- 介入呼吸內(nèi)鏡并發(fā)癥及處理
- 眼科手術(shù)器械清洗消毒滅菌技術(shù)操作規(guī)程
- 孕育優(yōu)質(zhì)寶寶的12堂成功課
- Qt5 C++ GUI Programming Cookbook
- 災(zāi)難醫(yī)學(xué):管理篇
- 常見惡性腫瘤治療原則與實(shí)施方案
- 復(fù)旦大學(xué)附屬華山醫(yī)院垂體疑難病多學(xué)科診治病例精選
- 麻醉安全與質(zhì)量管理
- 皮膚激光醫(yī)學(xué)原理及臨床應(yīng)用
- 向陽而生:柱子哥的抗癌指南
- 中國(guó)口腔種植體概覽
- 血吸蟲病監(jiān)測(cè)手冊(cè)