下面是我的剧本,其中有一个变量running_processes
,其中包含一个(一个或多个)PID列表
接下来,我读取每个pid的用户ID。到目前为止一切都很好。
然后我尝试使用curr_user_ids
在-debug module
变量中打印用户ID列表,这是当我收到错误消息:'dict object'没有属性'stdout_lines'
我期望curr_user_ids
包含一个或多个条目,如下面共享的输出所示。
- name: Get running processes list from remote host
shell: "ps -few | grep java | grep -v grep | awk '{print $2}'"
changed_when: false
register: running_processes
- name: Gather USER IDs from processes id before killing.
shell: "id -nu `cat /proc/{{ running_processes.stdout }}/loginuid`"
register: curr_user_ids
with_items: "{{ running_processes.stdout_lines }}"
- debug: msg="USER ID LIST HERE:{{ curr_user_ids.stdout }}"
with_items: "{{ curr_user_ids.stdout_lines }}"
TASK [Get running processes list from remote host] **********************************************************************************************************
task path: /app/wls/startstop.yml:22
ok: [10.9.9.111] => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"cmd": "ps -few | grep java | grep -v grep | awk '{print $2}'","delta": "0:00:00.166049","end": "2019-11-06 11:49:42.298603","rc": 0,"start": "2019-11-06 11:49:42.132554","stderr": "","stderr_lines": [],"stdout": "24032","stdout_lines": ["24032"]}
TASK [Gather USER IDS of processes id before killing.] ******************************************************************************************************
task path: /app/wls/startstop.yml:59
changed: [10.9.9.111] => (item=24032) => {"ansible_loop_var": "item","changed": true,"cmd": "id -nu `cat /proc/24032/loginuid`","delta": "0:00:00.116639","end": "2019-11-06 11:46:41.205843","item": "24032","start": "2019-11-06 11:46:41.089204","stdout": "user1","stdout_lines": ["user1"]}
TASK [debug] ************************************************************************************************************************************************
task path: /app/wls/startstop.yml:68
fatal: [10.9.9.111]: FAILED! => {"msg": "'dict object' has no attribute 'stdout_lines'"}
您能否建议我为什么会收到错误以及如何解决该错误?
谢谢