№ 9447 В разделе
Sysadmin
от September 28th, 2018,
В подшивках: Ansible, Linux, Security
This task regexps sshd_config for specific option and sets value to yes. If option not found it will be added to the end of file.
Options you want to change:
sshd_options: PubkeyAuthentication: "yes" PasswordAuthentication: "no"
Now remove from config all options you want to change:
- name: Remove all marked options from config become: yes lineinfile: path: "{{ sshd_config_path }}" state: absent regexp: '{{ item.key }}' with_dict: "{{ sshd_options }}" when: sshd_options != None and sshd_options is defined
Nice, now add your options to sshd config:
- name: Add marked options to config become: yes lineinfile: path: "{{ sshd_config_path }}" state: present line: '{{ item.key }} {{ item.value }}' with_dict: "{{ sshd_options }}" when: sshd_options != None and sshd_options is defined
If you want replace string option:
- name: Set PubkeyAuthentication = yes become: yes lineinfile: path: /etc/ssh/sshd_config regexp: '^PubkeyAuthentication no' line: 'PubkeyAuthentication yes'
Full sample here https://git.blindage.org/21h/ansible-library/src/branch/pubkey_sshd
Fortune cookie: Should I get locked in the PRINCICAL'S OFFICE today -- or have a VASECTOMY??
Leave a Reply