ansible 基礎入門

2021-10-07 13:49:23 字數 832 閱讀 6805

開始自動化運維工具ansible學習之路

ansible管理工具使用-m選項指定使用的模組,預設使用的是command模組

ansible host/hostgroups -m ping

ansible host/hostgroups -m command -a 『date』

cron有兩種狀態(state):present表示新增(可以省略),absent表示移除

ansible webservers -m cron -a 『minute="*/1" job="/bin/echo heihei name=「test cron job」』

ansible webservers -m cron -a 『name=「test cron job」 state=absent』

實現檔案的複製和批量下發檔案

ansible webservers -m copy -a 『src=/etc/fstab dest=/opt/fstab.bk owner=root mode=666』

ansible中的shell模組可以在被管理主機上執行命令

ansible webservers -m shell -a 『echo abc123 | passwd --stdin zhangsan』

將本地指令碼複製到被管理主機上進行執行

ansible webservers -m script -a 『test.sh』

用於模組收集、檢視被管理主機的facts

ansible webservers -m setup

乙個簡單的**是這麼建立的:

專案value

電腦$1600

手機$12

導管$1

ansible 基礎命令

ansible 命令總結 1.ad hoc 適合臨時執行任務 2.playbook 適合一些複雜的部署和配置環境 一 ad hoc 適合臨時執行任務 ansible doc l 檢視ansible的可用模組 1.pnig 檢查是否能聯通 2.yum 選項 name 安裝包名字 state 可以寫一些...

ansible 基礎模組

1 service systemd centos7推薦用systemd模組 name name.service 類似mysqld,nginx等 state started stoped reloaded restarted 動作 ed enabled yes 代表加入開機啟動 daemon relo...

ansible 基礎常用模組

修改 etc ansible hosts中新增組 a 192.168.122.60 192.168.122.68檢視模組用法 ansible doc s 模組名 ansible doc s copy ansible doc s fetchshell模組 file模組 在file模組中,path na...