我有以下角色:
---
- name: "Copying {{source_directory}} to {{destination_directory}}"
shell: cp -r "{{source_directory}}" "{{destination_directory}}"
使用方法如下:
- { role: copy_folder, source_directory: "{{working_directory}}/ipsc/dist", destination_directory: "/opt/apache-tomcat-base/webapps/ips" }
参数:working_directory: /opt/demoServer
这是在我使用此角色删除目录后执行的(因为我不想要以前的内容)
- name: "Removing Folder {{path_to_file}}"
command: rm -r "{{path_to_file}}"
参数:path_to_file: "/opt/apache-tomcat-base/webapps/ips"
我得到以下输出:
TASK: [copy_folder | Copying /opt/demoServer/ipsc/dist to /opt/apache-tomcat-base/webapps/ips] ***
<md1cat01-demo.lnx.ix.com> ESTABLISH CONNECTION FOR USER: my.user
<md1cat01-demo.lnx.ix.com> REMOTE_MODULE command cp -r "/opt/demoServer/ipsc/dist" "/opt/apache-tomcat-base/webapps/ips" #USE_SHELL
...
changed: [md1cat01-demo.lnx.ix.com] => {"changed": true, "cmd": "cp -r \"/opt/demoServer/ipsc/dist\" \"/opt/apache-tomcat-base/webapps/ips\"", "delta": "0:00:00.211759", "end": "2016-02-05 11:05:37.459890", "rc": 0, "start": "2016-02-05 11:05:37.248131", "stderr": "", "stdout": "", "warnings": []}
发生的事情是该目录中永远不会有文件夹。 基本上cp命令没有做它的工作,但我没有得到任何错误。如果我在机器上手动运行复制命令,则可以正常工作。