DevOps
  • DevOps
  • Docker
    • Overview
  • Vagrant
    • Overview
    • Installation
    • Basic Commands
    • Vagrantfile
      • Example
    • Deploying Multiple Machine
    • Distribution
    • Reference
  • Running SQL Server on Windows Docker
    • Introduction
      • Windows Container & Hyper-V Container
    • System Requirements and Prerequisites
    • Version Compatibility
    • Enable Hyper-V & Containers and Install Docker on Window Servers
    • Using Docker to Run MSSQL Image
    • Install SSMS for remoting MSSQL Server Image
    • Using Docker-Compose to Build Up a MSSQL Image
    • Increase the default Windows container's storage
    • Reference
    • Appendix
  • Kubernetes
    • Install Kubernetes with kubeasz
    • Use Hyper-V Manager to create VM for K8S
      • Specification of the VM
      • Use Hyper-V Manager to turn on a VM for K8S
    • Installation
      • Install VirtualBox and its extension on Ubuntu
      • Install kubectl
      • Install minikube
    • Getting Started
      • Running Kubernetes Locally via Minikube
    • Assign Memory Resources to Containers and Pods
    • Assign CPU Resources to Containers and Pods
    • Quality of Services (QoS)
    • Volume for Storage
      • Configure a Pod to Use a Volume for Storage
      • *Configure a Pod to Use a PersistentVolume for Storage
    • In a nutshell...
    • Reference
  • Ansible
    • What is Ansible?
    • Set Up OS Environments for Ansible
    • Install Ansible
    • Structure for ansible
      • Inventory
      • Playbook
      • Modules
      • Variables
      • Conditions
    • Security - Ansible Fault
    • 實際操作測試1 - 使用ssh
    • 實際操作測試2 - Docker容器部署
    • Appendix
    • Reference
  • Azure
    • Overview
    • Terms
    • Getting Started
    • Azure DevOps Services
    • Reference
Powered by GitBook
On this page

Was this helpful?

  1. Ansible
  2. Structure for ansible

Playbook

這裡就是Ansible的重頭戲了,你就是靠這份文件來控制伺服器一切的運作。

這份文件的格式是YAML,由於YAML高可讀性的特點,撰寫一份Playbook不是一件難事。

Ansible Playbook能夠做到事情實在有很多,執行程式碼、執行指令、安裝程式包,甚至開關程式也能做到。現在先講一下Playbook的格式:

#
-
  name: Execute command to display date on web_node1
  hosts: web_node1
  tasks:
    -
      name: Execute a date command
      command: date
-
  name: Execute a command to display hosts file contents on web_node2
  hosts: web_node2
  tasks:
    -
      name: Execute a command to display hosts file
      command: cat /etc/hosts

每一個執行程序都是一個dictionary,如果name跟host倒轉次序是沒有問題,但task中的次序就不可以了,因為task是一個list (在yaml中,list是有次序的!),因此請小心每個task執行的次序。上面的例子是用web_node1執行date來顯示web_node1中的日期,然後在web_node2執行cat來顯示web_node2中的/etc/hosts。

PreviousInventoryNextModules

Last updated 5 years ago

Was this helpful?