ansibl基本使用教程

一、安裝

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

yum install  ansible


二、基本使用

copy模塊:

    目的:把主控端/root目錄下的a.sh文件拷貝到到指定節點上

    命令:ansible all -m copy -a 'src=/root/a.sh dest=/tmp/'



file模塊:

    目的:更改指定節點上/tmp/t.sh的權限爲755,屬主和屬組爲root

    命令:ansible all -m file -a "dest=/tmp/t.sh mode=755 owner=root group=root"


cron模塊:

    目的:在指定節點上定義一個計劃任務,每隔3分鐘到主控端更新一次時間

    命令:ansible all -m cron -a 'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate 172.16.254.139"'



group模塊:

    目的:在所有節點上創建一個組名爲nolinux,gid爲2014的組

    命令:ansible all -m group -a 'gid=2014 name=nolinux'



user模塊:

    目的:在指定節點上創建一個用戶名爲nolinux,組爲nolinux的用戶

    命令:ansible all -m user -a 'name=nolinux groups=nolinux state=present'


yum模塊:

    目的:在指定節點上安裝 lrzsz 服務

    命令:ansible all -m yum -a "state=present name=httpd"



service模塊:

    目的:啓動指定節點上的 puppet 服務,並讓其開機自啓動

    命令:ansible all -m service -a 'name=puppet state=restarted enabled=yes'



script模塊:

    目的:在指定節點上執行/root/a.sh腳本(該腳本是在ansible控制節點上的)

    命令:ansible all -m script -a '/root/a.sh'



ping模塊:

    目的:檢查指定節點機器是否還能連通

    命令:ansible all -m ping




command模塊:

    目的:在指定節點上運行hostname命令

    命令:ansible all -m command -a 'hostname'


raw模塊:

    目的:在all節點上運行hostname命令

    命令:ansible all -m raw-a 'hostname|tee'


get_url模塊:

    目的:將http://10.1.1.116/favicon.ico文件下載到指定節點的/tmp目錄下

    命令:ansible all -m get_url -a 'url=http://10.1.1.116/favicon.ico dest=/tmp'




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章