1. [root@m01 scripts]# ansible oldboy -m copy -a "content='wo shi hao ren' dest=/machangwei/11"python
2. [root@web02 machangwei]# cat 11web
3. wo shi hao ren[root@web02 machangwei]# 應該加個換行符shell
4. bash
5. [root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen sha\n' dest=/machangwei/22"app
6. [root@web02 machangwei]# cat 22less
7. ni hen shapython2.7
8. [root@web02 machangwei]#ssh
[root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen\n' dest=/machangwei/33 owner=oldboy" tcp
[root@web02 machangwei]# ll
total 12
-rw-r--r-- 1 root root 14 Oct 22 12:32 11
-rw-r--r-- 1 root root 11 Oct 22 12:34 22
-rw-r--r-- 1 oldboy root 7 Oct 22 12:38 33
[root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen\n' owner=p group=incahome dest=/machangwei/44"
[root@web02 machangwei]# ll|tail -1
-rw-r--r-- 1 p incahome 7 Oct 22 12:47 44
[root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen\n' owner=p group=incahome dest=/machangwei/55 mode=1777"
[root@web02 machangwei]# ll|tail -1
-rwxrwxrwt 1 p incahome 7 Oct 22 12:50 55
[root@m01 scripts]# ansible oldboy -m copy -a "content='xiao ming\n' owner=p group=incahome dest=/machangwei/66 mode=1777"
[root@web02 machangwei]# cat 66
xiao
[root@web02 machangwei]# cat 66
xiao ming
=no 不傳送
[root@m01 scripts]# ansible oldboy -m copy -a "content='xiao ming\n' owner=p group=incahome dest=/machangwei/66 mode=1777 force=no"
[root@web02 machangwei]# cat 66
xiao ming
[root@web02 machangwei]# cat 66
xiao ming
[root@web02 machangwei]# cat 88
#!/bin/sh
cat >>/etc/ansible/hosts <<eof
[oldboy]
172.16.1.7
[root@m01 scripts]# ansible oldboy -m copy -a "src=/server/scripts/xiao owner=p group=incahome dest=/machangwei/88 mode=1777 backup=yes"
[root@web02 machangwei]# ls
11 22 33 44 55 66 77 88 88.4749.2017-10-22@13:15:11~
[root@web02 machangwei]# cat 88
123 456
[root@web02 machangwei]# cat 88.4749.2017-10-22\@13\:15\:11~
#!/bin/sh
cat >>/etc/ansible/hosts <<eof
[oldboy]
172.16.1.7
172.16.1.8
ansible oldboy -m copy -a "src=/server/scripts dest=/machangwei/"
[root@web02 machangwei]# ls
11 22 33 44 55 66 77 88 88.4749.2017-10-22@13:15:11~ scripts
[root@web02 machangwei]# cat scripts/
cat: scripts/: Is a directory
[root@web02 machangwei]# ll scripts/
total 28
-rw-r--r-- 1 root root 143 Oct 22 13:22 hosts
[root@m01 scripts]# ansible oldboy -m copy -a "src=/server/scripts dest=/machangwei/ directory_mode=0777" 遠端有目錄的權限不變,沒有
的建爲0777
[root@m01 scripts]# echo 45678 >mama
[root@m01 scripts]# cat mama
45678
[root@m01 scripts]# ansible oldboy -m copy -a "src=/server/scripts/mama dest=/machangwei/10"
[root@web02 machangwei]# cat 10
45678
copy模塊在ansible裏的角色就是把ansible執行機器上的文件拷貝到遠程節點上。
與fetch模塊相反的操做。
參數名 |
是否必須 |
默認值 |
選項 |
說明 |
src |
no |
|
|
用於定位ansible執行的機器上的文件,須要絕對路徑。若是拷貝的是文件夾,那麼文件夾會總體拷貝,若是結尾是」/」,那麼只有文件夾內的東西被考過去。一切的感受很像rsync |
content |
no |
|
|
用來替代src,用於將指定文件的內容,拷貝到遠程文件內 |
dest |
yes |
|
|
用於定位遠程節點上的文件,須要絕對路徑。若是src指向的是文件夾,這個參數也必須是指向文件夾 |
backup |
no |
no |
yes/no |
備份遠程節點上的原始文件,在拷貝以前。若是發生什麼意外,原始文件還能使用。 |
directory_mode |
no |
|
|
這個參數只能用於拷貝文件夾時候,這個設定後,文件夾內新建的文件會被拷貝。而老舊的不會被拷貝 |
follow |
no |
no |
yes/no |
當拷貝的文件夾內有link存在的時候,那麼拷貝過去的也會有link |
force |
no |
yes |
yes/no |
默認爲yes,會覆蓋遠程的內容不同的文件(可能文件名同樣)。若是是no,就不會拷貝文件,若是遠程有這個文件 |
group |
no |
|
|
設定一個羣組擁有拷貝到遠程節點的文件權限 |
mode |
no |
|
|
等同於chmod,參數能夠爲「u+rwx or u=rw,g=r,o=r」 |
owner |
no |
|
|
設定一個用戶擁有拷貝到遠程節點的文件權限 |
參數返回值
參數名 |
參數說明 |
返回值 |
返回值類型 |
樣例 |
src |
位於ansible執行機上的位置 |
changed |
string |
/home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source |
backup_file |
將原文件備份 |
changed and if backup=yes |
string |
/path/to/file.txt.2015-02-12@22:09~ |
uid |
在執行後,擁有者的ID |
success |
int |
100 |
dest |
遠程節點的目標目錄或文件 |
success |
string |
/path/to/file.txt |
checksum |
拷貝文件後的checksum值 |
success |
string |
6e642bb8dd5c2e027bf21dd923337cbb4214f827 |
md5sum |
拷貝文件後的md5 checksum值 |
when supported |
string |
2a5aeecc61dc98c4d780b14b330e3282 |
state |
執行後的狀態 |
success |
string |
file |
gid |
執行後擁有文件夾、文件的羣組ID |
success |
int |
100 |
mode |
執行後文件的權限 |
success |
string |
0644 |
owner |
執行後文件全部者的名字 |
success |
string |
httpd |
group |
執行後文件全部羣組的名字 |
success |
string |
httpd |
size |
執行後文件大小 |
success |
int |
1220 |
command 模塊用於運行系統命令,好比echo hello, 你安裝在系統裏的python,或者make 一類。你們能領悟就好了。
parameter |
required |
default |
choices |
comments |
chdir |
no |
|
|
運行command命令前先cd到這個目錄 |
creates |
no |
|
|
若是這個參數對應的文件存在,就不運行command |
executable |
no |
|
|
將shell切換爲command執行,這裏的全部命令須要使用絕對路徑 |
removes |
no |
|
|
若是這個參數對應的文件不存在,就不運行command |
[root@m01 scripts]# ansible oldboy -m command -a "ls" 家目錄
172.16.1.8 | SUCCESS | rc=0 >>
1.txt
2
2.txt
[root@m01 scripts]# ansible oldboy -m command -a "chdir=/machangwei/ ls"
172.16.1.31 | SUCCESS | rc=0 >>
10
11
1.t
22
33
44
55
66
77
88
[root@m01 scripts]# ansible oldboy -m command -a "touch creates /machangwei/cc"
[root@m01 scripts]# ansible oldboy -m command -a "touch /machangwei/aa creates"
主要是用來對定時任務進行調度,定時任務模塊會包含一句描述信息,格式以下:
"#Ansible: <name>" |
name對應的爲模塊傳遞過去的參數,主要用來給之後ansible進行操做的時候,查看相關的狀態或者檢查相關狀態
依賴的模塊爲cron
參數 |
必填 |
默認 |
選擇 |
說明 |
Backup |
非 |
|
Yes/no |
若是yes,那麼在修改以後會進行備份,備份的路徑在backup_file |
Cron_file |
非 |
|
|
若是設置了,那麼在cron.d中使用此文件替代單獨用戶的crontab,在使用此選項的時候,必須使用user選項 |
Day |
非 |
|
|
天 |
Hour |
非 |
|
|
小時 ( 0-23, *, */2, etc ) |
Job |
非 |
|
|
須要執行的命令,必須狀態爲present |
Minute |
非 |
|
|
分 ( 0-59, *, */2, etc ) |
Month |
非 |
|
|
月( 1-12, *, */2, etc ) |
Name |
非 |
|
|
任務的描述 |
Reboot |
非 |
No |
Yes/no |
重啓後是否須要執行 |
Special_time |
非 |
|
reboot yearly annually monthly weekly daily hourly |
特定的執行時間 |
State |
非 |
Present |
Present Absent |
啓用或停用任務 |
User |
非 |
Root |
|
執行任務的用戶 |
Weekday |
非 |
|
|
每一週的哪天進行運行(0-6 for Sunday-Saturday, *, etc) |
[root@m01 scripts]# ansible oldboy -m cron -a "name='chuang jian ding shi ren wu' minute=5 job='/bin/sh /machangwei/hostname.sh >/dev/null 2>&1'"
[root@web02 machangwei]# crontab -l|tail -2
#Ansible: chuang jian ding shi ren wu
5 * * * * /bin/sh /machangwei/hostname.sh >/dev/null 2>&1
[root@m01 scripts]# ansible oldboy -m cron -a "name='chuang jian ding shi ren wu' minute=5 job='/bin/sh /machangwei/hostname.sh >/dev/null 2>&1' state=absent"
[root@web02 machangwei]# crontab -l
#time sync by oldboy at 2010-2-1
*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
[root@web02 machangwei]#
[root@m01 scripts]# ansible oldboy -m cron -a "name='chuang jian ding shi ren wu' state=absent" 有名字就能夠
這個模塊在playbook中自動被查找的,從而獲得遠程主機的相關信息,能夠做爲變量使用。
參數 |
必填 |
默認 |
選擇 |
說明 |
Fact_path |
否 |
/etc/ansible/facts.d |
|
Fact的路徑 |
Filter |
否 |
* |
|
過濾串 |
[root@m01 scripts]# ansible oldboy -m setup -a "filter=ansible_eth[02]"
172.16.1.8 | SUCCESS => {
"ansible_facts": {
"ansible_eth0": {
"active": true,
"device": "eth0",
"features": {
"fcoe_mtu": "off [fixed]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "on",
"highdma": "off [fixed]",
"large_receive_offload": "off [fixed]",
"loopback": "off [fixed]",
"netns_local": "off [fixed]",
"ntuple_filters": "off [fixed]",
"receive_hashing": "off [fixed]",
"rx_checksumming": "on",
"rx_vlan_filter": "on [fixed]",
"rx_vlan_offload": "on [fixed]",
"scatter_gather": "on",
"tcp_segmentation_offload": "on",
"tx_checksum_fcoe_crc": "off [fixed]",
"tx_checksum_ip_generic": "on",
"tx_checksum_ipv4": "off",
"tx_checksum_ipv6": "off",
"tx_checksum_sctp": "off [fixed]",
"tx_checksum_unneeded": "off",
"tx_checksumming": "on",
"tx_fcoe_segmentation": "off [fixed]",
"tx_gre_segmentation": "off [fixed]",
"tx_gso_robust": "off [fixed]",
"tx_lockless": "off [fixed]",
"tx_scatter_gather": "on",
"tx_scatter_gather_fraglist": "off [fixed]",
"tx_tcp6_segmentation": "off",
"tx_tcp_ecn_segmentation": "off",
"tx_tcp_segmentation": "on",
"tx_udp_tnl_segmentation": "off [fixed]",
"tx_vlan_offload": "on [fixed]",
"udp_fragmentation_offload": "off [fixed]",
"vlan_challenged": "off [fixed]"
},
"ipv4": {
"address": "10.0.0.8",
"broadcast": "10.0.0.255",
"netmask": "255.255.255.0",
"network": "10.0.0.0"
},
"ipv6": [
{
"address": "fe80::20c:29ff:fecf:1335",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "00:0c:29:cf:13:35",
"module": "e1000",
"mtu": 1500,
"pciid": "0000:02:01.0",
"promisc": false,
"speed": 1000,
"type": "ether"
}
},
"changed": false
}
ansible pythonserver -m setup --tree /tmp/facts |
執行以後,會顯示相關的fact,而且在/tmp/facts中會保存fact信息,以下:
[root@ansibleserver tmp]# ls -l /tmp/facts/ total 12 -rw-r--r-- 1 root root 8990 Jan 18 13:16 192.168.1.60 |
使用--tree選項,在分類的時候,會根據主機的名稱進行分類
收集內存信息並輸出
[root@ansibleserver tmp]# ansible pythonserver -m setup -a "filter=ansible_*_mb"
SSH password:
192.168.1.60 | success >> {
"ansible_facts": {
"ansible_memfree_mb": 746,
"ansible_memtotal_mb": 996,
"ansible_swapfree_mb": 2015,
"ansible_swaptotal_mb": 2015
},
"changed": false
}
ping模塊主要是無心義的測試模塊,主要用來檢查ansible是否能夠用的模塊以及python是否配置好的,在playbook中基本不會使用,在能成功鏈接以後,老是返回結果pong
[root@m01 scripts]# ansible oldboy -m ping
172.16.1.8 | SUCCESS => {
"changed": false,
"ping": "pong"
}
用戶模塊主要用來管理用戶帳號和用戶的屬性(對遠程主機用戶進行批量管理)。
用戶模塊依賴的指令爲useradd,userdel,usermod
參數 |
必填 |
默認值 |
選項 |
說明 |
Append |
否 |
No |
Yes/no |
若是沒有指定group,append設定爲yes,那麼會添加到用戶同名組;append設定爲no,那麼會添加到user組。若是指定了group,那麼都會添加在指定的group組 |
Comment |
否 |
|
|
用戶的備註信息 |
Force |
否 |
No |
Yes/no |
當狀態爲absent的時候,至關於userdel -force |
generate_ssh_key |
否 |
No |
Yes/no |
是否生成祕鑰 |
Group |
否 |
|
|
可選的,設定用戶的主組 |
Groups |
否 |
|
|
用逗號分隔的組,當groups設定爲空的時候,那麼會移除除了主組的其餘全部組 |
Home |
否 |
|
|
可選的,設定爲用戶的home目錄 |
Login_class |
否 |
|
|
可選的,設定用戶的登陸類 FreeBSD, OpenBSD and NetBSD systems. |
Name |
是 |
|
|
用戶建立,移除,修改 |
Move_home |
否 |
No |
Yes/no |
若是使用了選項home=設置爲yes,那麼會將用戶家目錄移到不存在的home目錄中 |
Non_unique |
否 |
No |
Yes/no |
可選的,當使用-u選項的時候,將用戶的uid設置爲non_unique |
Password |
否 |
|
|
設定用戶的密碼 |
Remove |
否 |
No |
Yes/no |
當使用狀態爲state=absent的時候,差很少和userdel --remove(刪除全部信息) |
Shell |
否 |
|
|
設定用戶的shell |
Ssh_key_bits |
否 |
2048 |
|
設定祕鑰的位數 |
Ssh_key_comments |
否 |
¥HOSTHOME |
|
Ssh key備註信息 |
Ssh_key_file |
否 |
.sha/id_rsa |
|
祕鑰的文件名 |
ssh_key_passphrase |
否 |
|
|
Ssh祕鑰的密碼 |
Ssh_key_type |
否 |
Rsa |
|
Ssh祕鑰的類型 |
State |
否 |
Present |
Present Absent |
新增刪除 |
System |
否 |
No |
Yes/no |
建立爲系統帳號,不會改變已經存在的用戶 |
Uid |
否 |
|
|
設定爲用戶的uid |
Update_password |
否 |
Always |
Always On_create |
Always當用戶 |
[root@m01 scripts]# ansible oldboy -m user -a "name=xixi"
[root@web02 machangwei]# id xixi
uid=1003(xixi) gid=1003(xixi) groups=1003(xixi)
[root@m01 scripts]# ansible oldboy -m user -a "name=dong uid=576"
[root@web02 machangwei]# id dong
uid=576(dong) gid=576(dong) groups=576(dong)
[root@m01 scripts]# ansible oldboy -m user -a "name=nan group=xixi uid=579 comment='li li li'"
172.16.1.8 | SUCCESS => {
"changed": true,
"comment": "li li li",
"createhome": true,
"group": 1003,
"home": "/home/nan",
"name": "nan",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 579
}
[root@m01 scripts]# ansible oldboy -m user -a "name=bei group=xixi shell=/sbin/nologin/"
172.16.1.8 | SUCCESS => {
"changed": true,
"comment": "",
"createhome": true,
"group": 1003,
"home": "/home/bei",
"name": "bei",
"shell": "/sbin/nologin/",
"state": "present",
"system": false,
"uid": 1004
}
[root@m01 scripts]# ansible oldboy -m user -a "name=shang groups=xixi append=yes" 多個組
[root@m01 scripts]# ansible oldboy -m user -a "name=shang state=absent remove=yes"
將用戶強制刪除
在以前ansible命令行的時候有copy模塊,在playbook的時代天然也有一個模塊專門負責文件的拷貝,固然這個時代它不只僅是文件拷貝那麼簡單。
來自官方的解釋:
file模塊它包含了文件、文件夾、超級連接類的創立、拷貝、移動、刪除操做。
經常使用參數:
參數名 |
是否必須 |
默認值 |
選項 |
說明 |
follow |
no |
no |
yes/no |
若是原來的文件是link,拷貝後依舊是link |
force |
no |
no |
yes/no |
強制執行,沒說的 |
group |
no |
|
|
設定一個羣組擁有拷貝到遠程節點的文件權限 |
mode |
no |
|
|
等同於chmod,參數能夠爲「u+rwx or u=rw,g=r,o=r」 |
owner |
no |
|
|
設定一個用戶擁有拷貝到遠程節點的文件權限 |
path |
yes |
|
|
目標路徑,也能夠用dest,name代替 |
src |
yes |
|
|
待拷貝文件/文件夾的原始位置。 |
state |
no |
file |
file/link/directory/hard/touch/absent |
file表明拷貝後是文件;link表明最終是個軟連接;directory表明文件夾;hard表明硬連接;touch表明生成一個空文件;absent表明刪除 |
修改文件的全部組、人、權限。
- file: path=/etc/foo.conf owner=foo group=foo mode=0644
# 操做連接的案例
- file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
#參數化案例
- file: src=/tmp/{{ item.path }} dest={{ item.dest }} state=link
with_items:
- { path: 'x', dest: 'y' }
- { path: 'z', dest: 'k' }
# 使用touch來建立一個空文件並定義權限
- file: path=/etc/foo.conf state=touch mode="u=rw,g=r,o=r"
# touch一個空文件,而且修改權限
- file: path=/etc/foo.conf state=touch mode="u+rw,g-wx,o-rwx"
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/dong state=directory"
172.16.1.41 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/machangwei/dong",
"size": 4096,
"state": "directory",
"uid": 0
[root@web02 machangwei]# ls
bb cc dd dong hostname.sh
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/s/s/d/f state=directory"
172.16.1.31 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/machangwei/s/s/d/f",
"size": 4096,
"state": "directory",
"uid": 0
}
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/ming state=touch"
172.16.1.8 | SUCCESS => {
"changed": true,
"dest": "/machangwei/ming",
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"size": 0,
"state": "file",
"uid": 0
}
[root@m01 scripts]# ansible oldboy -m file -a "src=/machangwei/ming dest=/machangwei/sisi state=link"
172.16.1.8 | SUCCESS => {
"changed": true,
"dest": "/machangwei/sisi",
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"size": 16,
"src": "/machangwei/ming",
"state": "link",
"uid": 0
}
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/ming state=absent"
172.16.1.31 | SUCCESS => {
"changed": true,
"path": "/machangwei/ming",
"state": "absent"
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/a state=absent"
172.16.1.8 | SUCCESS => {
"changed": true,
"path": "/machangwei/a",
"state": "absent"
} a是多級目錄
[root@m01 scripts]# ansible oldboy -m fetch -a "src=/machangwei/bb dest=/server/scripts/"
172.16.1.8 | SUCCESS => {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/server/scripts/172.16.1.8/machangwei/bb",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"remote_md5sum": null
[root@m01 scripts]# ansible oldboy -m fetch -a "src=/machangwei/dong dest=/server/scripts/"
172.16.1.41 | SUCCESS => {
"changed": false,
"file": "/machangwei/dong",
"msg": "remote file is a directory, fetch cannot work on directories"目錄不可啦
[root@m01 scripts]# ansible oldboy -m fetch -a "src=/machangwei/bb dest=/server/scripts/"
172.16.1.8 | SUCCESS => {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/server/scripts/172.16.1.8/machangwei/bb",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"remote_md5sum": null
}
[root@m01 scripts]# ansible oldboy -m mount -a "fstype=nfs opts=ro src=172.16.1.31:/data path=/mnt state=mounted"
172.16.1.8 | SUCCESS => {
"changed": true,
"dump": "0",
"fstab": "/etc/fstab",
"fstype": "nfs",
"name": "/mnt",
"opts": "ro",
"passno": "0",
"src": "172.16.1.31:/data"
}
[root@web02 tmp]# tail -2 /etc/fstab
proc /proc proc defaults 0 0
172.16.1.31:/data /mnt nfs ro 0 0
卸載
[root@m01 scripts]# ansible oldboy -m mount -a "fstype=nfs opts=ro src=172.16.1.31:/data path=/mnt state=unmounted"
shell模塊和command模塊功能相似,可是shell模塊能夠識別一些特殊符號信息 > >> | * ^
[root@m01 scripts]# ansible oldboy -m shell -a "cd /machangwei;pwd;hostname"
172.16.1.41 | SUCCESS | rc=0 >>
/machangwei
backup
ansible oldboy -m yum -a "name=nmap state=installed"
參數名 |
是否必須 |
默認值 |
選項值 |
參數說明 |
conf_file |
不 |
|
|
設定遠程yum執行時所依賴的yum配置文件 |
disable_gpg_check |
不 |
No |
Yes/No |
在安裝包前檢查包,只會影響state參數爲present或者latest的時候 |
list |
No |
|
|
只能由ansible調用,不支持playbook,這個幹啥的你們都懂 |
name |
Yes |
|
|
你須要安裝的包的名字,也能如此使用name=python=2.7安裝python2.7 |
state |
no |
present |
present/latest/absent |
用於描述安裝包最終狀態,present/latest用於安裝包,absent用於remove安裝包 |
update_cache |
no |
no |
yes/no |
用於安裝包前執行更新list,只會影響state參數爲present/latest的時候 |
ansible oldboy -m service -a "name=crond state=stop enabled=no"
參考:
http://blog.csdn.net/kellyseeme/article/details/50539312
http://blog.csdn.net/wanghailong041/article/details/45770359
http://10786462.blog.51cto.com/10776462/1886774
- hosts: oldboy
tasks:
- name: step01
yum: name=rpcbind state=installed
- name: step02
yum: name=nfs-utils state=installed
- hosts: 172.16.1.31
tasks:
- name: step03
copy: content="/data/ 172.16.1.0/24(rw,sync)" dest=/etc/exports
- name: step04
shell: mkdir -p /data;chown nfsnobody.nfsnobody /data
- name: step05
command: /etc/init.d/rpcbind start
- name: step06
command: /etc/init.d/nfs start
- name: step07
shell: ps -ef|grep nfs
- name: step11
copy: content="wo hen shan liang" dest=/data/oldboy.txt
- hosts: nfs-C
tasks:
- name: step08
command: /etc/init.d/rpcbind start
- name: step09
shell: mount -t nfs 172.16.1.31:/data /mnt
- name: step10
command: df -h
- hosts: 172.16.1.7
tasks:
- name: step12
command: touch /mnt/11
- hosts: 172.16.1.8
tasks:
- name: step13
command: touch /mnt/22
- hosts: 172.16.1.41
tasks:
- name: step14
command: touch /mnt/33
- hosts: 172.16.1.31
tasks:
- name: step15
command: ls -l /data/