User Tools

Site Tools


ansible:ansible_tips

This is an old revision of the document!


Ansible tips and tricks

Replace inplace

Replace inplace sshd_config param (at same position)

Ex:

#Port 22
by
Port 2222
or 
Port 2233
---
- hosts: webservers
  tasks:
    - name: Update SSH configuration to be more secure.
      lineinfile:
        dest: /ansible/sshd_config
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
        state: present
      with_items:
        - regexp: '^(.*)PasswordAuthentication (.*)$'
          line: "PasswordAuthentication no"
        - regexp: '^(.*)PermitRootLogin (.*)$'
          line: "PermitRootLogin no"
        - regexp: '^(.*)Port (.*)$'
          line: "Port 2849"
ansible/ansible_tips.1740431250.txt.gz · Last modified: 2025/02/24 22:07 by manu