Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Ansible-搜索文件中的正则表达式字符串_Regex_String_Ansible - Fatal编程技术网

Regex Ansible-搜索文件中的正则表达式字符串

Regex Ansible-搜索文件中的正则表达式字符串,regex,string,ansible,Regex,String,Ansible,我需要搜索一个文件中的正则表达式字符串,当这是我想要回一条消息。搜索此字符串时遇到问题 有什么办法解决这个问题吗 - 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(

我需要搜索一个文件中的正则表达式字符串,当这是我想要回一条消息。搜索此字符串时遇到问题

有什么办法解决这个问题吗

- 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

感谢您的时间和支持

您能试试这个吗:

- 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.*")

你想匹配的模式是什么?“permitrotlogin no”这与两个单词之间有多少空格无关