有什么方法可以从ansible中启用extglob吗?
- name: copy files
sudo: yes
shell: shopt -s extglob但我错了:
failed: [host] => {"changed": true, "cmd": "shopt -s extglob", "delta": "0:00:00.001410", "end": "2015-10-20 09:10:36.438309", "rc": 127, "start": "2015-10-20 09:10:36.436899", "warnings": []}
stderr: /bin/sh: 1: shopt: not found
FATAL: all hosts have already failed -- aborting我需要使用extglob来运行这个命令。此命令不复制目录vendor。
cp -pav --parents `git diff --name-only master feature/deploy_2186 !(vendor)` /tmp/current该命令在终端上正常运行,但不能从ansible任务中运行。在阅读了一些文章之后,它需要启用extglob,所以我可以使用!(vendor)模式来执行供应商目录。
从无法执行的任务运行复制时出错
failed: [host] => {"changed": true, "cmd": "cp -pav --parents `git diff --name-only master new_release !(vendor)` /tmp/current", "delta": "0:00:00.003255", "end": "2015-10-20 09:22:16.387262", "rc": 1, "start": "2015-10-20 09:22:16.384007", "warnings": []}
stderr: fatal: ambiguous argument '!': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
cp: missing destination file operand after '/tmp/current'
Try 'cp --help' for more information.我的不可复制任务,如果我删除了!(vendor),它可以很好地工作,但是它里面有供应商:
- name: copy files
shell: cp -pav --parents `git diff --name-only master feature/deploy_2186 !(vendor)` /tmp/current
args:
chdir: /var/www
tags: release发布于 2015-10-21 07:51:08
有三种方法可以解决这个问题。
1)将命令放入shell脚本copy.sh并设置shell: copy.sh。
#!/bin/bash
shopt -s extglob
cp -pav --parents `git diff --name-only master feature/deploy_2186 !(vendor)` /tmp/current2)使用grep -v而不是extglob:
shell: cp -pav --parents `git diff --name-only master feature/deploy_2186 * | grep -v /vendor/` /tmp/current3)使用bash设置extglob并运行cp命令。您需要向ansible任务变量传递两行代码。因为语法是Yaml,所以它可以在shell字符串中嵌入换行符。你自己试试看。
shell: |
bash -c 'shopt -s extglob
cp -pav --parents `git diff --name-only master feature/deploy_2186 !(vendor)` /tmp/current'或
shell: "bash -c 'shopt -s extglob \n cp -pav --parents `git diff --name-only master feature/deploy_2186 !(vendor)` /tmp/current'"发布于 2015-10-20 12:54:39
您可能需要这样做,以便shopt和cp命令实际在同一个shell实例中运行:
- name: copy files
sudo: yes
shell: shopt -s extglob && cp -pav --parents `git diff --name-only master feature/deploy_2186 !(vendor)` /tmp/currenthttps://stackoverflow.com/questions/33232582
复制相似问题