我想使用Ansible创建一个zip打包功能,这是我的剧本:
---
- name: build lambda functions
hosts: localhost
- name: Buid Zip Package
command: zip -r functions/build/build-function.zip .
args:
chdir: functions/function-package/
我要打包的函数的代码位于functions/function-package/
中
我收到此错误:
> TASK [Buid Zip Package]
> ******************************************************** fatal: [localhost]: FAILED! => {"changed": false, "cmd": "zip -r
> functions/build/build-function.zip", "failed": true, "msg": "[Errno 2]
> No such file or directory", "rc": 2}
路径非常正确,我不知道还要检查什么!
该剧本在与目录/functions
这是文件的结构:
-- playbook.yml
-- /functions
-- /build
-- /function-package
-- script.py
-- lib
将zip放在/ build里面
答案 0 :(得分:0)
如果您在任务上使用chdir: functions/function-package
,那么您正在zip
目录中运行functions/function-package
命令。这意味着路径functions/build/build-function.zip
可能不再有效,因为您位于functions/
目录的子目录中。
根据您问题中的信息,适当的路径可能是../build/
,如下所示:
- name: build lambda functions
hosts: localhost
- name: Buid Zip Package
command: zip -r ../build/build-function.zip .
args:
chdir: functions/function-package/
更新
如果我复制您的目录布局:
$ find *
functions
functions/function-package
functions/function-package/script.py
functions/build
playbook.yml
并运行此剧本:
---
- hosts: localhost
gather_facts: false
tasks:
- name: Build Zip Package
command: zip -r ../build/build-function.zip .
args:
chdir: functions/function-package
效果很好:
$ ansible-playbook playbook.yml
PLAY [localhost] ******************************************************************************
TASK [Build Zip Package] **********************************************************************
changed: [localhost]
PLAY RECAP ************************************************************************************
localhost : ok=1 changed=1 unreachable=0 failed=0
并且.zip
文件按预期存在:
$ ls -l ./functions/build/build-function.zip
-rw-rw-r--. 1 lars lars 209 Jan 3 08:19 ./functions/build/build-function.zip