Ansible - Check if string exists in file

前端 未结 4 1917
再見小時候
再見小時候 2021-01-11 09:48

I\'m very new to Ansible

Is it possible to check if a string exists in a file using Ansible.

I want to check is a user has access to a server. this can be

4条回答
  •  青春惊慌失措
    2021-01-11 10:24

    I'd probably register and evaluate a variable.

    The following simple playbook works for me:

    - hosts: localhost
      tasks:
    
      - name: read the passwd file
        shell: cat /etc/passwd
        register: user_accts
    
      - name: a task that only happens if the user exists
        when: user_accts.stdout.find('hillsy') != -1
        debug: msg="user hillsy exists"
    

提交回复
热议问题