天天看點

ansible file子產品詳解

file子產品

專門用來設定檔案屬性;

force:需要在兩種情況下強制建立軟連結,一種是源檔案不存在,但之後會建立的情況下;另一種是目标軟連結已存在,需要先取消之前的軟鍊,然後建立新的軟鍊,有兩個選項:yes|no
group:定義檔案/目錄的屬組
mode:定義檔案/目錄的權限
owner:定義檔案/目錄的屬主
path:必選項,定義檔案/目錄的路徑
recurse:遞歸的設定檔案的屬性,隻對目錄有效
src:要被連結的源檔案的路徑,隻應用于state=link的情況
dest:被連結到的路徑,隻應用于state=link的情況

state:
=directory:如果目錄不存在,建立目錄
=file:即使檔案不存在,也不會被建立
=link:建立軟連結
=hard:建立硬連結
=touch:如果檔案不存在,則會建立一個新的檔案,如果檔案或目錄已存在,則更新其最後修改時間
=absent:删除目錄、檔案或者取消連結檔案      
$ ansible test -m file -a "path=/tmp/test state=touch owner=root group=root"      
$ ansible test -m file -a 'path=/tmp/www state=directory'
$ ansible test -m file -a "path=/tmp/tdir state=directory mode=0755"      

繼續閱讀