1. 程式人生 > >3、ansilbe常用模組詳解

3、ansilbe常用模組詳解

回顧:pxe, ansible

 

pxe:

網絡卡支援網路引導;

dhcp, filename, next-server

tftp-server

pxelinux.0

vmlinuz, initrd.img

menu.c32

pxelinux.cfg/default

 

system-config-kickstart

ksvalidator

 

ansible:

os provision:

物理機:pxe, cobbler

虛擬機器:image file template

configuration:

程式包管理、使用者管理、配置檔案、服務管理、cron任務等等;

puppet, saltstack, chef, cfengine

task exec

command and control

func, fabric

 

程式釋出:灰度模型

 

agent

agentless:

ssh服務;

 

ansible:

 

ansible <host-pattern> [-f forks] [-m module_name] [-a args]

args:

key=value

 

注意:command模組要執行命令無須為key=value格式,而是直接給出要執行的命令即可;

 

常用模組:

command

-a 'COMMAND'

user

-a 'name= state={present|absent} system= uid='

 

group

-a 'name= gid= state= system='

 

cron

-a 'name= minute= hour= day= month= weekday= job= user= state='

 

copy

-a 'dest= src= mode= owner= group='

 

file

-a 'path= mode= owner= group= state={directory|link|present|absent} src='

 

ping

沒有引數

 

yum

-a 'name= state={present|latest|absent}'

 

service

-a 'name= state={started|stopped|restarted} enabled='

 

shell

-a 'COMMAND'

 

script

-a '/path/to/script'

 

setup

 

playbook的核心元素:

tasks: 任務

variables: 變數

templates: 模板

handlers: 處理器

roles: 角色

 

變數:

facts

--extra-vars "name=value name=value"

role定義

Inventory中的變數:

主機變數

hostname name=value name=value

組變數

[groupname:vars]

name=value

name=value

 

Inventory的高階用法:

 

Playbook:

 

- host:

vars:

remote_user:

tasks:

-

-

-

variables:

-

-

-

handlers:

-

-

 

- host:

 

- host:

 

"ansible_distribution_major_version": "7",

 

nginx.conf

worker_processes {{ ansible_processor_cores * ansible_processor_count - 1 }};

 

實戰:用ansible playbook完成配置keepalived的叢集;

部落格:ansible的用法;