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

Ansible linux部署错误{“failed”quot;:true,“parsed”quot;:false},linux,bash,deployment,ssh,ansible,Linux,Bash,Deployment,Ssh,Ansible,我有3台linux机器,一台用于部署,两台用于部署应用程序。我用Ansible来解决这个问题。 在部署过程中的某个时刻,我希望远程执行这两台机器上的bash脚本 我有一个剧本,app_stop.yml,看起来像这样: ### rel/app_stop.yml # # Erlang app stop playbook - hosts: fe gather_facts: false sudo: app roles: - app_stop - name: Ping the

我有3台linux机器,一台用于部署,两台用于部署应用程序。我用Ansible来解决这个问题。 在部署过程中的某个时刻,我希望远程执行这两台机器上的bash脚本

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

### rel/app_stop.yml
#
# Erlang app stop playbook

-
  hosts: fe
  gather_facts: false
  sudo: app

  roles:
    - app_stop
- name: Ping the Erlang app
  command: "/home/deploy/script.bash"
  when: bin.stat.exists
  register: ping
  ignore_errors: yes
  sudo: yes
我的app_stop角色在某个时候有一个任务,当它从机器调用某个东西来ping应用程序时,谁将用pong响应。为了简化事情,我创建了一个bash脚本,它将回显pong,并尝试运行它。这给了我同样的错误

这是应用程序停止角色:

- 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\u错误:yes
是因为如果应用程序关闭,我将停止守护进程,如果没有,我将首先停止应用程序,然后停止守护进程

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.

正如chicks所指出的,您可以在命令任务中使用Ansible的“sudo”和“sudo_user”属性,这样会更干净

“应用程序停止”角色的第二个任务如下所示:

### rel/app_stop.yml
#
# Erlang app stop playbook

-
  hosts: fe
  gather_facts: false
  sudo: app

  roles:
    - 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,下面是我使用的代码

为区域设置定义一个变量很有趣,只是为了提高可重用性

这将是模板(i18n.j2):

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


我猜
setlocale
错误会破坏一些东西。你能摆脱它吗?我还需要ansible做
sudo
这样的描述。