華子目錄 Ansible四個(gè)命令模塊 1.組成 2.特點(diǎn) 3.區(qū)別 3.1`command、shell`模塊 3.2`raw`模塊 4.`command`模塊 4.1參數(shù)表 4.2`free_form`參數(shù) 5.`shell`模塊 6.`script`模塊 7.`raw`模塊 文件操作模塊
Ansible四個(gè)命令模塊
1.組成
2.特點(diǎn)
應(yīng)盡量避免
使用這三個(gè)模塊
來(lái)執(zhí)行命令,因?yàn)槠渌K大部分都是冪等性
的,可以自動(dòng)進(jìn)行更改跟蹤。冪等性
:輸入相同,輸出相同,無(wú)論多少次執(zhí)行
。比如說(shuō)確認(rèn)接口,如果傳入訂單號(hào),返回確認(rèn)ok
,如果已經(jīng)確認(rèn)過(guò)了
,再次調(diào)用確認(rèn)接口,返回如果還是確認(rèn)ok
,那么這個(gè)接口
就是滿(mǎn)足冪等性
command、shell、raw不具備冪等性
3.區(qū)別
3.1command、shell
模塊
相同點(diǎn):要求受管主機(jī)上安裝python
不同點(diǎn):command
可以在受管主機(jī)上執(zhí)行Linux命令
,但是不支持環(huán)境變量和操作符(例如'|' '<' '>' '&'
),shell模塊
需要調(diào)用/bin/sh
指令執(zhí)行
3.2raw
模塊
不需要受管主機(jī)安裝python
,直接使用遠(yuǎn)程shell
運(yùn)行命令,通常用于無(wú)法安裝python的系統(tǒng)(例如:網(wǎng)絡(luò)設(shè)備等)
4.command
模塊
4.1參數(shù)表
名稱(chēng) 必選 備注 chdir no(不是必選參數(shù)) 運(yùn)行command命令前先cd到這個(gè)目錄 creates no 如果這個(gè)參數(shù)對(duì)應(yīng)的文件存在,就不運(yùn)行command free_form yes 需要執(zhí)行的腳本(沒(méi)有真正的參數(shù)為free_form) executable no 改變用來(lái)執(zhí)行命令的shell,是可執(zhí)行文件的絕對(duì)路徑 removes no 如果這個(gè)參數(shù)對(duì)應(yīng)的文件不存在,就不運(yùn)行command,與creates參數(shù)作用相反 stdin no 2.4后的新增,將命令的stdin設(shè)置為指定的值
4.2free_form
參數(shù)
必須參數(shù)
,指定需要遠(yuǎn)程執(zhí)行的命令。
free_form 參數(shù)與其他參數(shù)(如果想要使用一個(gè)參數(shù),那么則需要為這個(gè)參數(shù)賦值,也就是name=value模式)并不相同。
如:需要在遠(yuǎn)程主機(jī)
上執(zhí)行 ls
命令時(shí),錯(cuò)誤
寫(xiě)法:free_form=ls
,因?yàn)椴?code>沒(méi)有任何參數(shù)的名字是 free_form
,若要在遠(yuǎn)程主機(jī)中執(zhí)行 ls
命令時(shí),直接
寫(xiě)成 ls
即可。因?yàn)?command
模塊的作用是執(zhí)行命令
,所以任何一個(gè)可以在遠(yuǎn)程主機(jī)上執(zhí)行的命令
都可以被稱(chēng)為free_form
例:
[ root@server ~]
@all:| --@ungrouped:| | --node1.example.com| | --node2.example.com
[ root@server ~]
node2.example.com | CHANGED | rc = 0 >>
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
node1.example.com | CHANGED | rc = 0 >>
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
[ root@server ~]
node2.example.com | CHANGED | rc = 0 >> node1.example.com | CHANGED | rc = 0 >>
[ root@server ~]
node2.example.com | CHANGED | rc = 0 >>
/root
node1.example.com | CHANGED | rc = 0 >>
/root
[ root@server ~]
node1.example.com | CHANGED | rc = 0 >> node2.example.com | CHANGED | rc = 0 >> [ root@node1 ~]
公共 文檔 模板 下載 anaconda-ks.cfg file.ansible[ root@node2 ~]
公共 模板 視頻 anaconda-ks.cfg file.ansible
[ root@server ~]
node1.example.com | SUCCESS | rc = 0 >>
skipped, since file.ansible existsDid not run command since 'file.ansible' exists
node2.example.com | SUCCESS | rc = 0 >>
skipped, since file.ansible existsDid not run command since 'file.ansible' exists
[ root@server ~]
node2.example.com | CHANGED | rc = 0 >>
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
file.ansible
node1.example.com | CHANGED | rc = 0 >>
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
[ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
hello world > file.ansible
node2.example.com | CHANGED | rc = 0 >>
hello world > file.ansible
[ root@server ~]
node2.example.com | CHANGED | rc = 0 >> node1.example.com | CHANGED | rc = 0 >> [ root@server ~]
node2.example.com | FAILED | rc = 2 >>
file.ansible/root:
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
file.ansiblels: 無(wú)法訪問(wèn) '|' : 沒(méi)有那個(gè)文件或目錄
ls: 無(wú)法訪問(wèn) 'grep' : 沒(méi)有那個(gè)文件或目錄non-zero return code
node1.example.com | FAILED | rc = 2 >>
file.ansible/root:
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xzls: 無(wú)法訪問(wèn) '|' : 沒(méi)有那個(gè)文件或目錄
ls: 無(wú)法訪問(wèn) 'grep' : 沒(méi)有那個(gè)文件或目錄non-zero return code
5.shell
模塊
5.1作用
讓遠(yuǎn)程主機(jī)
在shell進(jìn)程
下執(zhí)行命令
,從而支持shell的特性
,如管道等
,參數(shù)
與command模塊
幾乎相同,但在執(zhí)行命令的時(shí)候調(diào)用
的是/bin/sh
5.2例如
[ root@server ~]
node2.example.com | CHANGED | rc = 0 >>
.
├── 公共
├── 模板
├── 視頻
├── 圖片
├── 文檔
├── 下載
├── 音樂(lè)
├── 桌面
├── anaconda-ks.cfg
└── file.ansible8 directories, 2 files
node1.example.com | CHANGED | rc = 0 >>
.
├── 公共
├── 模板
├── 視頻
├── 圖片
├── 文檔
├── 下載
├── 音樂(lè)
├── 桌面
├── anaconda-ks.cfg
├── file.ansible
├── frp_0.56.0_linux_amd64
│ ├── frpc
│ ├── frpc.toml
│ └── LICENSE
├── frp_0.56.0_linux_amd64.tar.gz
└── mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz9 directories, 7 files
[ root@server ~]
node1.example.com | CHANGED | rc = 0 >> [ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
hello world
6.script
模塊
script
與shell
類(lèi)似,都可以執(zhí)行腳本區(qū)別
:script
執(zhí)行的腳本在ansible管理機(jī)
上,而shell
執(zhí)行的腳本必須先放到目標(biāo)節(jié)點(diǎn)
上去,才能執(zhí)行shell
執(zhí)行可以使用環(huán)境變量
,bash
等,但是script
只是執(zhí)行.sh
腳本,不能帶 bash
6.1示例
在server
端寫(xiě)一個(gè)t2.sh
的腳本
[ root@server ~]
echo "hello world" [ root@server ~]
node2.example.com | CHANGED = > { "changed" : true,"rc" : 0 ,"stderr" : "Shared connection to node2.example.com closed.\r \n " ,"stderr_lines" : [ "Shared connection to node2.example.com closed." ] ,"stdout" : "hello world\r \n " ,"stdout_lines" : [ "hello world" ]
}
node1.example.com | CHANGED = > { "changed" : true,"rc" : 0 ,"stderr" : "Shared connection to node1.example.com closed.\r \n " ,"stderr_lines" : [ "Shared connection to node1.example.com closed." ] ,"stdout" : "hello world\r \n " ,"stdout_lines" : [ "hello world" ]
}
[ root@node1 ~]
echo "hello world" [ root@node2 ~]
echo "hello world" [ root@server ~]
node2.example.com | CHANGED | rc = 0 >>
hello world
node1.example.com | CHANGED | rc = 0 >>
hello world
7.raw
模塊
raw
模塊主要用于執(zhí)行一些低級(jí)
的命令,一般適用于下列兩種場(chǎng)景
第一種
:在較老的(python2.4和之前的版本
)主機(jī)上執(zhí)行命令第二種
:對(duì)任何
沒(méi)有安裝python
的設(shè)備(如路由器
)注意:在任何其他情況
下,使用shell
或command
模塊更為合適
7.1參數(shù)
名稱(chēng) 必選 備注 executable no(可以不選) 改變用來(lái)執(zhí)行命令的shell,是可執(zhí)行文件的絕對(duì)路徑 free_form yes 需要執(zhí)行的腳本(沒(méi)有真正的參數(shù)為free_form)
7.2示例
[ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
/root
Shared connection to node1.example.com closed.node2.example.com | CHANGED | rc = 0 >>
/root
Shared connection to node2.example.com closed.
[ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
hello world
Shared connection to node1.example.com closed.node2.example.com | CHANGED | rc = 0 >>
hello world
Shared connection to node2.example.com closed.
文件操作模塊
1.file
模塊
作用:實(shí)現(xiàn)對(duì)文件的基本操作
,如:創(chuàng)建
目錄或文件,刪除
目錄或文件,修改文件權(quán)限
等
1.1參數(shù)
path
:必須參數(shù)
,用于指定
要操作的文件
或目錄
,在之前版本的ansible
中,使用dest參數(shù)
或者name參數(shù)
指定要操作的文件或目錄
,為了兼容之前的版本
,使用dest
或name
也可以state:
格式
:path=“路徑” state= touch | directory | link | hard | absent
此參數(shù)
使用靈活,如:在遠(yuǎn)程主機(jī)
中創(chuàng)建一個(gè)目錄
,則使用path參數(shù)
指定對(duì)應(yīng)的目錄路徑
,假設(shè)在遠(yuǎn)程主機(jī)上創(chuàng)建/testdir/a/b
目錄,則設(shè)置路徑:path=/testdir/a/b
,但ansible
無(wú)法從/testdir/a/b
這個(gè)路徑看出b
是一個(gè)文件
還是一個(gè)目錄
,所以需要通過(guò)state
參數(shù)進(jìn)行說(shuō)明
參數(shù) 值 含義 state=
absent
刪除
遠(yuǎn)程機(jī)器上的指定文件
或目錄
state=
directory
創(chuàng)建
一個(gè)空目錄
state=
file
查看
指定目錄
是否存在
state=
touch
創(chuàng)建
一個(gè)空文件
state=
hard/link
創(chuàng)建
鏈接文件
src
:當(dāng)state
設(shè)置為link
或者hard
時(shí),表示創(chuàng)建一個(gè)軟鏈
或硬鏈
,則必須通過(guò)指明src參數(shù)
即可指定鏈接源
force
: 當(dāng)state=link
的時(shí),使用force=yes
參數(shù)表示強(qiáng)制
創(chuàng)建鏈接文件
,該文件
分為三種情況
:
當(dāng)要?jiǎng)?chuàng)建的鏈接文件
指向的源文件
并不存在
時(shí),使用此參數(shù),可以先強(qiáng)制
創(chuàng)建出鏈接文件
當(dāng)存儲(chǔ)目錄
中已經(jīng)存在
與鏈接文件
同名的文件
時(shí),會(huì)將同名文件
覆蓋為鏈接文件
,相當(dāng)于刪除同名文件
,創(chuàng)建鏈接文件
當(dāng)你要?jiǎng)?chuàng)建鏈接文件
的目錄
中已經(jīng)存在
與鏈接文件
同名的文件,并且鏈接文件指向的源文件
也不存在,這時(shí)會(huì)強(qiáng)制替換
同名文件為鏈接文件
owner
:用于指定被操作文件的屬主信息
,屬主
對(duì)應(yīng)的用戶(hù)
必須在遠(yuǎn)程主機(jī)中存在
,否則會(huì)報(bào)錯(cuò)
group
:用于指定
被操作文件的屬組
,屬組
對(duì)應(yīng)的組
必須在遠(yuǎn)程主機(jī)
中存在,否則會(huì)報(bào)錯(cuò)
mode
:用于指定
被操作文件
的權(quán)限
,如:
要將文件權(quán)限
設(shè)置為: “rw-r-x---
”,則可以使用mode=650
進(jìn)行設(shè)置,或者使用mode=0650
要設(shè)置特殊權(quán)限
,如:為二進(jìn)制文件
設(shè)置suid
,則可以使用mode=4700
recurse
:當(dāng)要操作的文件
為目錄
時(shí),recurse
設(shè)置為yes
可以遞歸
的修改
目錄中文件的屬性
和權(quán)限
1.2示例
在所有遠(yuǎn)程主機(jī)
上創(chuàng)建一個(gè)名為 data
的目錄,如果存在
則不做操作
[ root@server ~]
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"gid" : 0 ,"group" : "root" ,"mode" : "0755" ,"owner" : "root" ,"path" : "/root/data" ,"size" : 6 ,"state" : "directory" ,"uid" : 0
}
node2.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"gid" : 0 ,"group" : "root" ,"mode" : "0755" ,"owner" : "root" ,"path" : "/root/data" ,"size" : 6 ,"state" : "directory" ,"uid" : 0
} [ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
data
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
t2.sh
node2.example.com | CHANGED | rc = 0 >>
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
data
file.ansible
t2.sh
在node1
主機(jī)上創(chuàng)建一個(gè)名為testfile1
的文件,如果testfile1
文件已經(jīng)存在,則會(huì)更新
文件的時(shí)間戳
,與touch
命令的作用相同
[ root@server ~]
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/data/testfile1" ,"gid" : 0 ,"group" : "root" ,"mode" : "0644" ,"owner" : "root" ,"size" : 0 ,"state" : "file" ,"uid" : 0
} [ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
file1
testfile1
在node1
上為testfile1
文件創(chuàng)建軟鏈接
文件,軟鏈接
名為linkfile1
[ root@server ~]
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/data/linkfile1" ,"gid" : 0 ,"group" : "root" ,"mode" : "0777" ,"owner" : "root" ,"size" : 20 ,"src" : "/root/data/testfile1" ,"state" : "link" ,"uid" : 0
} [ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
file1
linkfile1
testfile1
在node1
上為 testfile1
文件創(chuàng)建硬鏈接
文件,硬鏈接
名為 hardfile1
(類(lèi)似于復(fù)制
)
[ root@server ~]
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/data/hardfile1" ,"gid" : 0 ,"group" : "root" ,"mode" : "0644" ,"owner" : "root" ,"size" : 0 ,"src" : "/root/data/testfile1" ,"state" : "hard" ,"uid" : 0
} [ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
file1
hardfile1
linkfile1
testfile1
在創(chuàng)建鏈接
文件時(shí),如果源文件
不存在,或者鏈接文件與其他文件同名
時(shí),強(qiáng)制覆蓋同名文件
或者創(chuàng)建鏈接文件
,參考上述force
參數(shù)的解釋
[ root@server ~]
[ WARNING] : Cannot set fs attributes on a non-existent symlink target. follow should be
set to False to avoid this.
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/data/linkfile3" ,"src" : "/root/data/123"
} [ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
file1
hardfile1
linkfile1
linkfile3
testfile1
[ root@server ~]
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"path" : "/root/data" ,"state" : "absent"
} [ root@server ~]
node1.example.com | CHANGED | rc = 0 >>
公共
模板
視頻
圖片
文檔
下載
音樂(lè)
桌面
anaconda-ks.cfg
file.ansible
frp_0.56.0_linux_amd64
frp_0.56.0_linux_amd64.tar.gz
mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
t2.sh
創(chuàng)建文件
或目錄
的時(shí)候指定屬主
,或者修改遠(yuǎn)程主機(jī)
上的文件或目錄的屬主
[ root@server ~]
node2.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile1" ,"gid" : 0 ,"group" : "root" ,"mode" : "0644" ,"owner" : "redhat" ,"size" : 0 ,"state" : "file" ,"uid" : 1000
}
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile1" ,"gid" : 0 ,"group" : "root" ,"mode" : "0644" ,"owner" : "redhat" ,"size" : 0 ,"state" : "file" ,"uid" : 1000
} [ root@server ~]
node2.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile2" ,"gid" : 0 ,"group" : "root" ,"mode" : "0644" ,"owner" : "root" ,"size" : 0 ,"state" : "file" ,"uid" : 0
}
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile2" ,"gid" : 0 ,"group" : "root" ,"mode" : "0644" ,"owner" : "root" ,"size" : 0 ,"state" : "file" ,"uid" : 0
}
[ root@server ~]
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile2" ,"gid" : 1000 ,"group" : "redhat" ,"mode" : "0644" ,"owner" : "redhat" ,"size" : 0 ,"state" : "file" ,"uid" : 1000
}
node2.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile2" ,"gid" : 1000 ,"group" : "redhat" ,"mode" : "0644" ,"owner" : "redhat" ,"size" : 0 ,"state" : "file" ,"uid" : 1000
}
創(chuàng)建文件或目錄
的時(shí)候指定權(quán)限
,或者修改遠(yuǎn)程主機(jī)
上的文件或目錄的權(quán)限
[ root@server ~]
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile1" ,"gid" : 0 ,"group" : "root" ,"mode" : "0777" ,"owner" : "redhat" ,"size" : 0 ,"state" : "file" ,"uid" : 1000
}
node2.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"dest" : "/root/testfile1" ,"gid" : 0 ,"group" : "root" ,"mode" : "0777" ,"owner" : "redhat" ,"size" : 0 ,"state" : "file" ,"uid" : 1000
}
遞歸
方式將目錄中的文件
的屬主屬組
都設(shè)置為redhat
[ root@server ~]
node2.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"gid" : 1000 ,"group" : "redhat" ,"mode" : "0755" ,"owner" : "redhat" ,"path" : "/data/test/demo" ,"size" : 6 ,"state" : "directory" ,"uid" : 1000
}
node1.example.com | CHANGED = > { "ansible_facts" : { "discovered_interpreter_python" : "/usr/bin/python3" } ,"changed" : true,"gid" : 1000 ,"group" : "redhat" ,"mode" : "0755" ,"owner" : "redhat" ,"path" : "/data/test/demo" ,"size" : 6 ,"state" : "directory" ,"uid" : 1000
} [ root@node1 ~]
總用量 0
drwxr-xr-x 2 redhat redhat 6 7 月 7 22 :15 demo[ root@node2 ~]
總用量 0
drwxr-xr-x 2 redhat redhat 6 7 月 7 22 :15 demo
2.copy模塊
作用:拷貝文件
,將ansible
主機(jī)上的文件
拷貝到遠(yuǎn)程受控
主機(jī)中
2.1參數(shù)
參數(shù) 默認(rèn)值 含義 src 用于指定需要copy
的文件或目錄 backup no,yes 當(dāng)遠(yuǎn)程主機(jī)的目標(biāo)路徑中已存在同名文件
,并且與ansible
主機(jī)中的文件內(nèi)容不同時(shí),是否對(duì)遠(yuǎn)程主機(jī)的文件進(jìn)行備份,設(shè)為yes
時(shí),會(huì)先備份遠(yuǎn)程主機(jī)中的文件,然后再拷貝到遠(yuǎn)程主機(jī) content 當(dāng)不使用src指定拷貝的文件時(shí),可以使用content直接指定文件內(nèi)容,src與content兩個(gè)參數(shù)必有其一,否則會(huì)報(bào)錯(cuò) dest 用于指定文件將被拷貝到遠(yuǎn)程主機(jī)的哪個(gè)目錄中,dest為必須參數(shù) group 指定文件拷貝到遠(yuǎn)程主機(jī)后的屬組,但是遠(yuǎn)程主機(jī)上必須有對(duì)應(yīng)的組,否則會(huì)報(bào)錯(cuò) owner 指定文件拷貝到遠(yuǎn)程主機(jī)后的屬主,但是遠(yuǎn)程主機(jī)上必須有對(duì)應(yīng)的用戶(hù),否則會(huì)報(bào) mode 錯(cuò)文指定文件拷貝到遠(yuǎn)程主機(jī)后的權(quán)限,如果你想將權(quán)限設(shè)置為"rw-r–r–",則可以使用mode=0644表示,如果你想要在user對(duì)應(yīng)的權(quán)限位上添加執(zhí)行權(quán)限,則可以使用mode=u+x表示 force no,yes 當(dāng)遠(yuǎn)程主機(jī)的目標(biāo)路徑中已經(jīng)存在同名文件,并且與ansible主機(jī)中的文件內(nèi)容不同時(shí),是否強(qiáng)制覆蓋,默認(rèn)值為yes,表示覆蓋,如果設(shè)置為no,則不會(huì)執(zhí)行覆蓋拷貝操作,遠(yuǎn)程主機(jī)中的文件保持不變