- Security Automation with Ansible 2
- Madhu Akula Akash Mahajan
- 234字
- 2021-07-02 21:59:51
YAML syntax for writing Ansible playbooks
Ansible playbooks are written in YAML, which stands for YAML Ain't Markup Language.
According to the official document (http://yaml.org/spec/current.html):
YAML Ain’t Markup Language
(abbreviated YAML) is a data serialization language designed to be human-friendly and work well with modern programming languages for everyday tasks.
Ansible uses YAML because it is easier for humans to read and write than other common data formats, such as XML or JSON. All YAML files (regardless of their association with Ansible or not) can optionally begin with --- and end with .... This is part of the YAML format and indicates the start and end of a document.
YAML files should end with .yaml or .yml. YAML is case sensitive.
You can also use linters, such as www.yamllint.com, or your text editor plugins for linting YAML syntax, which help you to troubleshoot any syntax errors and so on.
Here is an example of a simple playbook to showcase YAML syntax from Ansible documentation (http://docs.ansible.com/ansible/playbooks_intro.html#playbook-language-example):
- hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root
tasks: - name: Ensure apache is at the latest version yum:
name: httpd
state: latest - name: Write the apache config file template:
src: /srv/httpd.j2
dest: /etc/httpd.conf
notify: - restart apache
- name: Ensure apache is running (and enable it at boot) service:
name: httpd
state: started
enabled: yes
handlers: - name: Restart apache service:
name: httpd
state: restarted
- 高效能辦公必修課:Word圖文處理
- 現(xiàn)代測(cè)控電子技術(shù)
- R Data Mining
- 7天精通Dreamweaver CS5網(wǎng)頁(yè)設(shè)計(jì)與制作
- Visual FoxPro 6.0數(shù)據(jù)庫(kù)與程序設(shè)計(jì)
- TestStand工業(yè)自動(dòng)化測(cè)試管理(典藏版)
- Python Data Science Essentials
- Photoshop CS3圖像處理融會(huì)貫通
- C語(yǔ)言開(kāi)發(fā)技術(shù)詳解
- Docker High Performance(Second Edition)
- Godot Engine Game Development Projects
- MPC5554/5553微處理器揭秘
- 數(shù)字多媒體技術(shù)與應(yīng)用實(shí)例
- 軟件質(zhì)量管理實(shí)踐
- SQL Server 2019 Administrator's Guide