Ansible 使用 awk 提取 shell 输出

问题描述

---
- name: Data Collection
  hosts: all
  tasks:
    - name: List all users
      shell: "cat /etc/passwd | awk -F: '{print $1}'"
      register: users
    - lineinfile:
        dest: /tmp/users.csv
        create: yes
        line: "The {{ inventory_hostname}},{{ users.stdout }}"
      delegate_to: localhost

没有给出预期的输出,因为我在 shell 模块中使用 awk / grep 时遇到语法错误。请参考预期的输出。

172.17.254.201,root
172.17.254.201,bin
172.17.254.201,nobody
172.17.254.201,test1
172.17.254.201,test2
172.17.254.202,root
172.17.254.202,bin
172.17.254.202,nobody
172.17.254.202,test1
172.17.254.202,test2
..

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)