简体   繁体   English

从两个列表的连接中设置一个事实

[英]set ansible fact from concatenation of two lists

I wish to combine the output of two commands into one new variable that i can use as args for another command: 我希望将两个命令的输出合并到一个新变量中,以用作另一个命令的args:

---
- hosts: '{{target}}'
  tasks:

    - name: determine storage nfs mount points
      shell: /usr/sbin/showmount -d | grep -v Directories
      register: nfs
      ignore_errors: yes

    - debug: var=nfs.stdout_lines

    - name: determine storage xrd mount points
      shell: df | grep /xrd | awk '{print $6}'
      register: xrd

    - debug: var=xrd.stdout_lines

    - name: determine all mount points
      set_fact: mounts="{{ nfs.stdout_lines }} + {{ xrd.stdout_lines }}"

    - name: run gather script
      script: gather.py {{mounts.stdout_lines|join(" ")}} > /tmp/gather.txt
      register: gather

however, when i run it it comes out with: 但是,当我运行它时,结果如下:

PLAY [ltda-srv050] *************************************************************

TASK [setup] *******************************************************************
ok: [ltda-srv050]

TASK [determine storage nfs mount points] **************************************
fatal: [ltda-srv050]: FAILED! => {"changed": true, "cmd": "/usr/sbin/showmount -d | grep -v Directories", "delta": "0:00:00.011269", "end": "2016-09-14 23:48:14.489385", "failed": true, "rc": 1, "start": "2016-09-14 23:48:14.478116", "stderr": "clnt_create: RPC: Program not registered", "stdout": "", "stdout_lines": [], "warnings": []}
...ignoring

TASK [debug] *******************************************************************
ok: [ltda-srv050] => {
    "nfs.stdout_lines": []
}

TASK [determine storage xrd mount points] **************************************
changed: [ltda-srv050]

TASK [debug] *******************************************************************
ok: [ltda-srv050] => {
    "xrd.stdout_lines": [
        "/xrd/cache1",
        "/xrd/cache2",
        "/xrd/cache3",
        "/xrd/cache4",
        "/xrd/cache5",
        "/xrd/cache6",
        "/xrd/cache7",
        "/xrd/cache8",
        "/xrd/cache9",
        "/xrd/cache10",
        "/xrd/cache11"
    ]
}

TASK [determine all mount points] **********************************************
ok: [ltda-srv050]

TASK [run gather script] *******************************************************
fatal: [ltda-srv050]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'stdout_lines'\n\nThe error appears to have been in '/afs/slac.stanford.edu/u/sf/ytl/work/storage/gather_file_attributes/retrieve_file_attributes.yml': line 21, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: run gather script\n      ^ here\n"}

NO MORE HOSTS LEFT *************************************************************
 [WARNING]: Could not create retry file 'retrieve_file_attributes.retry'.         [Errno 2] No such file or directory: ''


PLAY RECAP *********************************************************************
ltda-srv050                : ok=6    changed=1    unreachable=0    failed=1

help...? 救命...?

mounts已经是一个列表,因此删除它尝试在其上调用.stdout_lines失败-删除.stdout_lines有效:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM