Skip to content

Instantly share code, notes, and snippets.

@iAugur
Last active May 14, 2024 12:37
Show Gist options
  • Save iAugur/ecd6cd79d51d2cbef56871b27893f3f2 to your computer and use it in GitHub Desktop.
Save iAugur/ecd6cd79d51d2cbef56871b27893f3f2 to your computer and use it in GitHub Desktop.

Revisions

  1. iAugur revised this gist Jan 10, 2017. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion ansible-add-string-to-line.yml
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,14 @@
    backup: yes
    dest: /etc/ssh/sshd_config
    regexp: '^(AllowGroups(?!.*\b{{ sftp_group_name }}\b).*)$'
    replace: '\1 {{ sftp_group_name }}'
    replace: '\1 {{ sftp_group_name }}'

    # This could also be achieved using the line in file module:
    - name: Add Group to AllowGroups
    lineinfile:
    dest=/etc/ssh/sshd_config
    backup=True
    backrefs=True
    state=present
    regexp='^(AllowGroups(?!.*\b{{ sftp_group_name }}\b).*)$'
    line='\1 {{ sftp_group_name }}'
  2. iAugur created this gist Jan 10, 2017.
    13 changes: 13 additions & 0 deletions ansible-add-string-to-line.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # Adapted from solution provided by http://stackoverflow.com/users/57719/chin-huang http://stackoverflow.com/a/31465939/348868
    # Scenario: You want to add a group to the list of the AllowGroups in ssh_config
    # before:
    # AllowGroups Group1
    # After:
    # AllowGroups Group1 Group2

    - name: Add Group to AllowGroups
    replace:
    backup: yes
    dest: /etc/ssh/sshd_config
    regexp: '^(AllowGroups(?!.*\b{{ sftp_group_name }}\b).*)$'
    replace: '\1 {{ sftp_group_name }}'