1. 程式人生 > >ansible模塊

ansible模塊

root lin mnt started light 硬盤 -m bsp nbsp

1、/etc/ansible/hosts 文件配置如下:

[group01]				//ubuntu16
jumper ansible_ssh_port=6666 ansible_ssh_host=172.16.1.206
172.16.1.207
[group01]				//centos7
172.16.1.201		

2、遠程重啟服務

sudo ansible group01 –m service –a “name=ssh state=restarted”

3、查看遠程主機名

sudo ansible group01 –m command –a “hostname”

4、復制文件

sudo ansible group01 -m copy –a “src=/home/test.txt dest=/tmp owner=root group=root mode=0755”

5、下載文件到遠程主機的指定目錄

sudo ansible group01 –m get_url –a “url=http://www.baidu.com dest=/tmp mode=0440 force=yes”

6、linux平臺安裝軟件

 sudo ansible group01 –m apt –a “pkg=tree state=latest”          //ubuntu安裝
 sudo ansible group02 –m yum –a “name=tree state=latest”          //centos安裝

7、cron模塊

sudo ansible group01 –m cron –a ”name=’check dirs’ hour=’5,2’  job=’ls -al’”

8、mount模塊:遠程主機掛載硬盤

sudo ansible group01 –m mount –a “name=/mnt/data src=/dev/sd0 fstype=ext4 opts=ro state=present”

9、user模塊

# 添加用戶
sudo ansible group01 –m user –a “name=jeff comment=’Jefflee’”

# 刪除用戶
sudo ansible group01 –m user –a “name=jeff state=absent remove=yes”

ansible模塊