Ansible - Check if string exists in file

前端 未结 4 1920
再見小時候
再見小時候 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:16

    If you want to fail if there is no user:

    tasks:
      - shell: grep username /etc/passwd
        changed_when: false
    

    By default shell module will fail if command exit code is non zero.
    So it will give you ok if username is there and fails otherwise.
    I use changed_when: false to prevent changed state when grepping.

提交回复
热议问题