Skip to content

Add validate option to lineinfile module to edit the sshd config file in chapter 10 #273

@geerlingguy

Description

@geerlingguy

To prevent users from blowing up their SSH server configuration and locking them out from their servers, we can add a validate to the lineinfile example modifying the sshd_config file in Chapter 10. For example, we created the following task in the May 20 Ansible 101 livestream (see #269):

    - name: Make sure SSH is more secure.
      lineinfile:
        dest: /etc/ssh/sshd_config
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
        state: present
        validate: 'sshd -t -f %s'
      with_items:
        - regexp: "^PasswordAuthentication"
          line: "PasswordAuthentication no"
        - regexp: "^PermitRootLogin"
          line: "PermitRootLogin no"
        - regexp: "^Port"
          line: "Port 2849"
      notify: restart ssh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions