Ansible常用模組模板

2021-10-02 06:30:38 字數 2004 閱讀 7626

ansible+主機名稱±m(指定模組)+模組名稱±a(模組動作)+「具體命令」

-hosts:指定組

-name: install ***

yum:

name: ***

state: latest(安裝最新)absent(刪除)present(安裝)

exclude: 排除

disablerepo: 安裝時不使用哪個倉庫

enablerepo:指定哪個倉庫安裝

yum_repository

-name: add ***repo

yum_repository

name:倉庫名稱

description:描述

baseurl:倉庫位址 http:// https:// ftp:// file://

-name: configure *** 

copy:

src: 本機配置檔案位址

dest: 控制端配置檔案位址

owner: 屬主

group:屬組

mode: '許可權'

content :要寫入的內容

backup: 每次變更備份

-name : 服務名稱

state : started stopped restarted reloaded

enabled: 是否開機啟動 yes/no

cron:        

name:

weekday:

minute:

hour:

user: 使用者

job:"/bin/bash /scripts/check_data.sh &>/dev/null" 執行定時任務

- name: mount *** server

mount:

src: 172.16.1.31:/data/ansible 遠端機掛載

path: /mnt 掛載到控制機的哪個目錄

fstype: nfs 掛載系統型別

opts: defaults 選項

state: 永久

臨時

file:

path: /在被控端哪個路徑下建立目錄或檔案

state: /directory (建立目錄) touch(建立檔案)

owner: 屬主

group:屬組

mode:許可權

recurse: yes 遞迴授權

name:  指定使用者名稱 

uid: 指定使用者的uid

group: 指定使用者的組名稱或組id

groups: 指定使用者的附加組(附加組需存在)

create__home: 建立使用者家目錄預設yes

shell: /bin/bash 指定登陸使用者的bash

system: 指定系統使用者

name: 組名稱

state: present absent

gid: 組id

命令模組 (command不支援管道符,建議使用shell模組)
-name: disiable selinux

selinux:

state:disabled

-name:firewalld

firewalld:

zone: 指定區域預設public

service: 指定服務名稱

port: 指定埠

state: 啟用或禁止

masquerade: 開機位址偽裝預設yes

immediate: 臨時生效預設yes

permanent: 永久生效

source: **ip

Ansible常用模組

1.ping模組2.ansible command模組是ansible預設模組,主要用於執行linux基礎命令,可以執行遠端伺服器命令執行 任務執行等操作。但command模組不支援變數 重定向 管道符等,這些操作需要用shell模組執行 command模組使用詳解 chdir 執行命令前,切換到目...

ansible常用模組

1.setup 該模組主要用於收集資訊,是通過呼叫facts元件來實現的 ansible doc s setup ansible mysql m setup 檢視mysql伺服器上所有資訊檢視遠端主機基本資訊 ansible all m setup2.ping測試遠端主機執行狀態 ansible a...

Ansible 常用模組

ansible是基於python開發,集合了眾多運維工具 puppet cfengine chef func fabric 的優點 具有批量系統配置 批量程式部署 批量執行命令等功能。是基於模組工作的,本身沒有批量部署的能力。真正具有批量部署的是ansible所執行的模組,ansible只是提供一種...