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

Inventory

Inventory簡單來說就是你的伺服器清單,當中包括了伺服器位址和連接設定。

A fully-featured inventory file can serve as the source of truth for your network. Using an inventory file, a single playbook can maintain hundreds of network devices with a single command. This page shows you how to build an inventory file, step by step.

Ansible 2.8 Documentation

沒錯,只要你的Inventory file設定好,所有在Inventory中的伺服器都任你指揮!

基本的Inventory可以這樣設定:

# you can specify the user and ssh port number of this server
# Inventory Parameters
# ansible_connection=ssh/winrm/local
# ansible_port=22
# ansible_user=root/administrator
# ansible_ssh_pass=password

web1 ansible_host=webserver.com ansible_connection=ssh ansible_user=webuser ansible_ssh_pass=webPass!
localhost ansible_connection=local

Parameters

Description

Specification

ansible_connection

連接其他伺服器或本機的方式

ssh,winrm,local

ansible_port

連接伺服器的連接埠號碼

1-65536(default:22)

ansible_user

連接伺服器的用戶

username

ansible_ssh_paa

使用ssh連接伺服器時用戶的密碼

password

ansible_password

使用winrm連接伺服器時用戶的密碼

password

上面的例子指定了本機及另一台伺服器的設定,然後你就能使用playbook開始自動化你的工作了!

如果你有好多台伺服器,你亦可以做一份複雜的inventory來實現不同的群組設定。以下是一個例子:

# Web Servers
web_node1 ansible_host=web01.xyz.com ansible_connection=winrm ansible_user=administrator ansible_password=Win$Pass
web_node2 ansible_host=web02.xyz.com ansible_connection=winrm ansible_user=administrator ansible_password=Win$Pass
web_node3 ansible_host=web03.xyz.com ansible_connection=winrm ansible_user=administrator ansible_password=Win$Pass
# DB Servers
sql_db1 ansible_host=sql01.xyz.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Lin$Pass
sql_db2 ansible_host=sql02.xyz.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Lin$Pass
# Groups
[db_nodes]
sql_db1
sql_db2
[web_nodes]
web_node1
web_node2
web_node3
[boston_nodes]
sql_db1
web_node1
[dallas_nodes]
sql_db2
web_node2
web_node3
[us_nodes:children]
boston_nodes
dallas_nodes

這個例子中,webserver都是以Windows作為OS運作,而且都在web_nodes群組;資料庫則使用Linux系統,歸類在db_nodes。而它們亦有以地方作為類別分組,sql_db1及web_node1在boston_nodes中;其餘則在dallas_nodes當中,而最後的us_nodes就包括兩個地方的nodes,即是所有的伺服器都在us_nodes當中。

PreviousStructure for ansibleNextPlaybook

Last updated 5 years ago

Was this helpful?

Inventory設定