Ansible linux部署错误{“failed”:true,“parsed”:false}

我有3台Linux机器,一台用于部署,另外两台用于部署应用程序。 我使用Ansible这个,我有一个问题。 在我的部署过程中,我想远程执行这两台机器上的bash脚本。

我有一个playbook,app_stop.yml,看起来像这样:

### rel/app_stop.yml # # Erlang app stop playbook - hosts: fe gather_facts: false sudo: app roles: - app_stop 

我的app_stopangular色有一个任务,当它从机器调用某些东西来ping应用程序,谁会用pong响应。 为了简化事情,我创build了一个bash脚本来回应pong,并且尝试运行它。 它给了我同样的错误。

这是app_stopangular色:

 - name: Is the Erlang app installed? stat: path="{{ app_install_dir }}/{{ app_name_short }}/bin/{{ app_name_short }}" register: bin - name: Ping the Erlang app command: "sudo /home/deploy/script.bash" when: bin.stat.exists == true register: ping ignore_errors: yes - name: Stop the Erlang app command: "sudo -u {{ app_user }} {{ app_install_dir }}/{{ app_name_short }}/bin/{{ app_name_short }} stop" when: ping is defined and ping.stdout.find("pong") != -1 ignore_errors: yes - name: Determine the ERTS bin folder path shell: "ls {{ app_install_dir }}/{{ app_name_short }}/erts-*/bin/epmd" when: bin.stat.exists == true register: epmd ignore_errors: yes - name: Stop the Erlang port mapping daemon (epmd) command: "sudo -u {{ app_user }} {{ epmd.stdout_lines[0] }} -kill" ignore_errors: yes when: epmd.stdout_lines is defined 

第二个任务是重要的。 我有ignore_errors: yes的原因是,如果应用程序closures,我会停止守护进程,如果不是,我会先停止应用程序,然后守护进程。

Ping Erlang应用程序失败,即使我没有做任何Erlang进程的东西,我只调用一个打印pong的shell脚本。 (和它工作,如果我手动连接与SSH)。

我和Ansible得到的错误是下一个:

 failed: [stefan1] => {"failed": true, "parsed": false} /bin/sh: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory [sudo] password for deploy: {"changed": true, "end": "2015-12-24 03:04:55.207125", "stdout": "", "cmd": ["sudo", "/home/deploy/script.bash"], "start": "2015-12-24 02:59:55.095913", "delta": "0:05:00.111212", "stderr": "", "rc": 1, "warnings": []} OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /home/stefan-work-tiefighter-dev/.ssh/config debug1: /home/stefan-work-tiefighter-dev/.ssh/config line 8: Applying options for * debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: auto-mux: Trying existing master debug2: fd 3 setting O_NONBLOCK debug2: mux_client_hello_exchange: master version 4 debug3: mux_client_forwards: request forwardings: 0 local, 0 remote debug3: mux_client_request_session: entering debug3: mux_client_request_alive: entering debug3: mux_client_request_alive: done pid = 100975 debug3: mux_client_request_session: session request sent debug1: mux_client_request_session: master session id: 2 debug3: mux_client_read_packet: read header failed: Broken pipe debug2: Received exit status from master 0 Shared connection to 192.168.0.201 closed. 

小鸡指出,你可以在Command任务上使用Ansible的“sudo”和“sudo_user”属性,它会更干净。

“app_stop”角色的第二项任务如下所示:

 - name: Ping the Erlang app command: "/home/deploy/script.bash" when: bin.stat.exists register: ping ignore_errors: yes sudo: yes 

关于你得到的错误信息,这是从操作系统抱怨没有正确设置的语言环境。 我以前遇到同样的问题,我通常使用一个Ansible任务来确保基于模板文件正确配置区域设置。

从你的输出中,我猜你正在使用CentOS,所以这是我使用的代码。

为locale定义一个变量很有意思,只是为了提高可重用性。

这将是模板( i18n.j2 ):

 LANG="{{ locale }}" SYSFONT="latarcyrheb-sun16" LC_CTYPE="{{ locale }}" 

这将是配置CentOS使用的任务:

 - name: Ensure language and locale are correct template: src="i18n.j2" dest="/etc/sysconfig/i18n" sudo: yes