Ansible:转义引号并列出用户密码到期信息
如何在shell模块报价中转义? 我试过如下方法:Ansible:转义引号并列出用户密码到期信息,ansible,Ansible,如何在shell模块报价中转义? 我试过如下方法: - name: UList shell: "cut -f 1 -d: /etc/passwd | sudo xargs -n 1 -I {} bash -c \" echo {} ; chage -l {}\"" 及 哪里出了错?这本剧本对我很有用,希望它也能对你有所帮助。如果您在转义“引号时遇到问题,可以对命令使用单引号” 要么这样做 'cut-f1-d:/etc/passwd | sudo xargs-n1-I{}bash-c“ech
- name: UList
shell: "cut -f 1 -d: /etc/passwd | sudo xargs -n 1 -I {} bash -c \" echo {} ; chage -l {}\""
及
哪里出了错?这本剧本对我很有用,希望它也能对你有所帮助。如果您在转义
“
引号时遇到问题,可以对命令使用单引号”
要么这样做
'cut-f1-d:/etc/passwd | sudo xargs-n1-I{}bash-c“echo{};chage-l{}'
或
“cut-f1-d:/etc/passwd | sudo xargs-n1-I{}bash-c'echo{};chage-l{}'
两个都在工作,我已经测试过了
---
- name: Set my hosts variable
hosts: localhost
tasks:
- name: UList
shell: 'cut -f 1 -d: /etc/passwd | sudo xargs -n 1 -I {} bash -c " echo {} ; chage -l {}"'
register: result
- name: debug
debug:
msg: "{{result}}"
或
对于您希望使用的输出
awk-F':''{system(“echo”$1”和&chage-l“$1)}'/etc/passwd
你能告诉我你想用上面的命令实现什么吗?我想列出系统中所有用户的用户名和密码过期信息。已解决。谢谢。@kurgulus Welcome…:)
---
- name: Set my hosts variable
hosts: localhost
tasks:
- name: UList
shell: 'cut -f 1 -d: /etc/passwd | sudo xargs -n 1 -I {} bash -c " echo {} ; chage -l {}"'
register: result
- name: debug
debug:
msg: "{{result}}"
---
- name: Set my hosts variable
hosts: localhost
tasks:
- name: UList
shell: "awk -F':' '{ system(\"echo \" $1 \" && chage -l \" $1) }' /etc/passwd"
register: result
- name: debug
debug:
msg: "{{result}}"