1. 程式人生 > 實用技巧 >Ansible命令模組(unarchive模組 archive模組 )

Ansible命令模組(unarchive模組 archive模組 )

1.unarchive 解壓模組

1)幫助語法

- name: Unarchive a file that is already on the remote machine
  unarchive:
    src: /tmp/foo.zip            #要解壓的包
    dest: /usr/local/bin        #解壓到目標位置
    remote_src: 
        yes                        #要解壓的包在受控端
        no                        #要解壓的包在控制端

2)例項

#1.解壓控制端的包到受控端
[root@m01 
/package]# ansible web01 -m unarchive -a 'src=/package/php.tar.gz dest=/tmp/' #2.解壓受控端的包到受控端 [root@m01 /package]# ansible web03 -m unarchive -a 'src=/package/php.tar.gz dest=/tmp/ remote_src=yes'

2.archive 壓縮模組

1)幫助語法

EXAMPLES:
- name: Compress directory /path/to/foo/ into /path/to/foo.tgz
  archive:
    path: /path/to/foo            #要壓縮的檔案或目錄
    dest: 
/path/to/foo.tgz #壓縮後的檔案 format:bz2, gz, tar, xz, zip #指定打包的型別

2)例項

#1.打包站點目錄
[root@m01 /package]# ansible web01 -m archive -a 'path=/code dest=/tmp/code.tar.gz'