如何在Ansible Playbook中基于stdout / stderr返回代码运行命令

时间:2018-10-15 15:59:25

标签: ansible

我有一本食谱,要创建一个集群(请参见下面的两个剧本),我想要做的是,基于返回代码,我希望能够运行“ chef-backend-ctl join-cluster”,但是我遇到错误:

 - name: check if we can run create-cluster, or if the cluster is already attached
    command: "chef-backend-ctl status > /dev/null 2>&1"
    register: status
  - debug: msg="{{ status.stdout }}"

  - name: create-cluster if chef-backend-ctl status failed
    command: "chef-backend-ctl join-cluster '{{hostvars[groups['chef_be1_cluster'][0]].be1_ip}}' -s /home/ec2-user/chef-backend-secrets.json --yes --accept-license"
    when: status.stdout == 1

错误:

TASK [check if we can run create-cluster, or if the cluster is already attached] *********************************************************************************************************************************
fatal: [10.1.1.4]: FAILED! => {"changed": true, "cmd": ["chef-backend-ctl", "status", ">", "/dev/null", "2>&1"], "delta": "0:00:00.414671", "end": "2018-10-15 15:50:27.891275", "msg": "non-zero return code", "rc": 1, "start": "2018-10-15 15:50:27.476604", "stderr": "", "stderr_lines": [], "stdout": "Unknown service or system component: >", "stdout_lines": ["Unknown service or system component: >"]}
    to retry, use: --limit @/home/ec2-user/ANSIBLE/clusterOps/roles/chef-cluster-be2/defaults/main.retry

0 个答案:

没有答案