I need to search regex string in a file, when this is fulfilled I want a message back. I have problems searching for this string.
Any ideas to solve this?
- hosts: localhost
tasks:
name: check PermitRootLogin
shell: "sudo cat /etc/ssh/sshd_config"
register: check_ssh
- debug:
msg: 'This server is ok'
when: check_ssh.splitlines()|select('match', '^PermitRootLogin\s*no\s*')|list
thanks for your time and support
Can you try this one:
- hosts: localhost
tasks:
name: check PermitRootLogin
shell: "sudo cat /etc/ssh/sshd_config"
register: check_ssh
- debug:
msg: 'This server is ok'
when: check_ssh.stdout is match("^PermitRootLogin.*no.*")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.