@@ -1,26 +1,25 @@
+---
- name: Check that the controller's ssh config file exists
- stat:
+ ansible.builtin.stat:
path: "{{ sshconfig }}"
register: ssh_config
-# Check if the include directive is already presetn
-- name: Check if the kdevops include directive was used
- lineinfile:
+- name: Check that the kdevops Include directive is present
+ ansible.builtin.lineinfile:
path: "{{ sshconfig }}"
regexp: "Include ~/.ssh/config_kdevops_*"
state: absent
- check_mode: yes
+ check_mode: true
changed_when: false
register: kdevops_ssh_include
when: ssh_config.stat.exists
-# Check if the the kdevops_version was added in a comment
-- name: Check if the new include directive was used with a kdevops_version comment
- lineinfile:
+- name: Check that the Include directive has a kdevops_version comment
+ ansible.builtin.lineinfile:
path: "{{ sshconfig }}"
regexp: "^#(.*)kdevops_version(.*)"
state: absent
- check_mode: yes
+ check_mode: true
changed_when: false
register: fixed_ssh_entry
when: ssh_config.stat.exists
@@ -28,28 +27,28 @@
# If both the include directive was found and kdevops version comment was found
# we bail right away to avoid updating the ssh config file always.
- name: Check if the new fixed include directive was used
- meta: end_play
+ ansible.builtin.meta: end_play
when:
- ssh_config.stat.exists
- kdevops_ssh_include.found
- fixed_ssh_entry.found
- name: Remove the stale Include directive
- lineinfile:
+ ansible.builtin.lineinfile:
path: "{{ sshconfig }}"
line: "Include ~/.ssh/config_kdevops_*"
state: absent
when: ssh_config.stat.exists
-- name: Remove any stale kdevops comments
- lineinfile:
+- name: Remove stale kdevops comments
+ ansible.builtin.lineinfile:
path: "{{ sshconfig }}"
regexp: "^#(.*)kdevops(.*)"
state: absent
when: ssh_config.stat.exists
-- name: Remove any extra new lines
- replace:
+- name: Remove extraneous extra new lines
+ ansible.builtin.replace:
path: "{{ sshconfig }}"
regexp: '(^\s*$)'
replace: ''
@@ -57,12 +56,13 @@
# ssh include directives must follow a new line.
- name: Add a proper Include directive to {{ sshconfig }}
- blockinfile:
+ ansible.builtin.blockinfile:
path: "{{ sshconfig }}"
insertbefore: BOF
marker: "{mark}"
marker_begin: "# Automatically added by kdevops\n# kdevops_version: {{ kdevops_version }}"
marker_end: ""
create: true
+ mode: "u=rw,g=r,o=r"
block: |
Include ~/.ssh/config_kdevops_*