Ansible playbook无法运行补丁

我正在尝试使用Ansible来configurationVagrant虚拟机。 VM正在运行CentOS 6.4。 我正在使用以下(缩写)ansible剧本:

- hosts: default vars: home: '/home/vagrant' curl_version: '7_19_7' curl_url: 'https://github.com/bagder/curl/archive/curl-{{ curl_version }}.tar.gz' curl_dir: '{{ home }}/curl-curl-{{ curl_version }}' # user: vagrant remote_user: vagrant sudo: yes tasks: - name: Ensure required packages and installed and up to date - pt1 yum: pkg={{ item }} state=present with_items: - make - gcc - etc... # Lots more yum tasks in here - name: Ensure CURL source downloaded get_url: url={{ curl_url }} dest=/home/vagrant/curl-{{ curl_version }}.tar - name: Extract CURL source command: tar -zxf {{ home }}/curl-{{ curl_version }}.tar creates={{ curl_dir }} - name: Copy ssh patch over copy: src=./files/ssh.c.patch dest={{ home }}/ssh.c.patch - name: Patch CURL with openssl command: '"{{ item }}" chdir={{ curl_dir }}/lib' with_items: - patch {{ curl_dir }}/lib/ssh.c {{ home }}/ssh.c.patch 

Vagrangt工作正常,Ansible剧本成功运行到最后一个任务“使用openssl修补CURL” – 失败,如下所示:

 TASK: [Patch CURL with openssl] *********************************************** failed: [default] => (item=patch < /home/vagrant/ssh.c.patch) => {"cmd": ["patch < /home/vagrant/ssh.c.patch"], "failed": true, "item": "patch < /home/vagrant/ssh.c.patch", "rc": 2} msg: [Errno 2] No such file or directory FATAL: all hosts have already failed -- aborting 

我已经validation到目前为止的所有任务都能正常工作,并且文件被下载并提取到预期的位置。

任务失败后,如果SSH进入正在configuration的虚拟机,并自己运行相同的事情 – 使用剧本variables中的确切值,它将起作用:

 cd /home/vagrant/curl-curl-7_19_7 sudo patch /home/vagrant/curl-curl-7_19_7/lib/ssh.c /home/vagrant/ssh.c.patch 

我是Ansible的新手,我不确定为什么这不起作用 – 它看起来应该是? 我究竟做错了什么?

它看起来像你在你的“命令”调用中使用shellredirect小于号(但它被ServerFaultparsing器吃掉)。 尝试使用“shell”而不是“命令”那里。 命令不通过shell,所以shellredirect和pipe道的东西将无法正常工作。 壳牌应该工作。

@Tybstar的回答指出了我的正确方向 – 使用shell而不是command 。 实际的修复是从这个改变补丁任务:

 - name: Patch CURL with openssl command: '"{{ item }}" chdir={{ curl_dir }}/lib' with_items: - patch {{ curl_dir }}/lib/ssh.c {{ home }}/ssh.c.patch 

对此:

 - name: Patch CURL with openssl shell: patch {{ curl_dir }}/lib/ssh.c {{ home }}/ssh.c.patch chdir={{ curl_dir }}/lib