直接执行不行
[root@test shell]# ansible server9 -m shell -a "cat /etc/passwd|grep -v 'nologin\|shutdown\|sync\|halt'|awk -F : '{print $1}'"
server9 | SUCCESS | rc=0 >>
root:x:0:0:root:/root:/bin/bash
test:x:1000:1000:osa:/home/osa:/bin/bash
audit:x:1001:1001::/home/audit_user:/bin/bash
在于awk内的引号问题,需要转义
[root@test shell]# ansible server9 -m shell -a "cat /etc/passwd|grep -v 'nologin\|shutdown\|sync\|halt'|awk -F : '{print \$1}'"
server9 | SUCCESS | rc=0 >>
root
test
audit