条件检查“ user_sdf_exist.rc == 0”失败

时间:2019-12-16 07:59:09

标签: ansible

我有以下剧本,它仅在一台服务器上失败,并且在所有服务器上都没有任何错误

---
- hosts: user_host
  tasks:
  - name: check sdf user exists
    command: grep -Fq "sdf" /etc/passwd
    register: user_sdf_exist
    ignore_errors: True
    changed_when: False

 - name: check authorized_keys file exits
    stat: path=/home/sdf/.ssh/authorized_keys
    register: authorized_keys_file
    when: user_sdf_exist.rc == 0

关注是我收到的错误

fatal: [xxx.xxx.xxx.xxx]:FAILED! => {"failed": true, "msg": "The conditional check 'user_sdf_exist.rc == 0' failed. The error was: error while evaluating conditional (user_sdf_exist.rc == 0): 'dict object' has no attribute 'rc'\n\nThe error appears to have been in '/home/sdf/bin/configs/ansible/playbooks/roles/ansible_pub_key_for_sdf/tasks/main.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: check authorized_keys file exits\n  ^ here\n"}

但是,仅针对该主机运行该Playbook时,该Playbook会通过并返回user_sdf_exist.rc ==0。我们拥有一个cron,它将在所有主机上每隔一小时运行一次此Playbook,在此期间,Playbook仅在此主机上失败一位主持人。

输出

TASK [debug] *******************************************************************
ok: [xxx.xxx.xxx.xxx] => {
    "msg": {
        "changed": false, 
        "cmd": [
            "grep", 
            "-Fq", 
            "sdf", 
            "/etc/passwd"
        ], 
        "delta": "0:00:00.175056", 
        "end": "2019-12-11 12:58:50.601619", 
        "rc": 0, 
        "start": "2019-12-11 12:58:50.426563", 
        "stderr": "", 
        "stdout": "", 
        "stdout_lines": [], 
        "warnings": []
    }
}

1 个答案:

答案 0 :(得分:1)

代替# ------------------------------------------------------------------------------ # | Cross-domain AJAX requests | # ------------------------------------------------------------------------------ # Enable cross-origin AJAX requests. # http://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity # http://enable-cors.org/ # <IfModule mod_headers.c> # Header set Access-Control-Allow-Origin "*" # </IfModule> # Header set Header set Access-Control-Allow-Origin "*" # Header always set Access-Control-Allow-Credentials "true" Access-Control-Allow-Origin "http://your-page.com:80" Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT" Header always set Access-Control-Allow-Headers "My-First-Header,My-Second-Header,Authorization, content-type, csrf-token"
您需要使用when: user_sdf_exist.rc == 0