From e7fe212fba59441e871f9abff57da28cfe81bda3 Mon Sep 17 00:00:00 2001 From: David Lopez Date: Thu, 27 Jul 2023 09:13:19 +0000 Subject: [PATCH] Update create_user_ssh/check_authorizzed_key.yml --- create_user_ssh/check_authorizzed_key.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/create_user_ssh/check_authorizzed_key.yml b/create_user_ssh/check_authorizzed_key.yml index 3bd019b..00444d9 100644 --- a/create_user_ssh/check_authorizzed_key.yml +++ b/create_user_ssh/check_authorizzed_key.yml @@ -18,15 +18,16 @@ debug: msg: "Authorized key exists: {{ authorized_key_exists | default(false) }}" - - name: Add authorized key - authorized_key: - user: root # Replace with the remote user's name - state: present - key: "{{ key_to_add }}" - + - name: Add authorized key if it does not exist + block: + - name: Add authorized key + authorized_key: + user: root # Replace with the remote user's name + state: present + key: "{{ key_to_add }}" rescue: - name: Handle error when key already exists debug: msg: "The authorized key already exists. Skipping addition." - when: not authorized_key_exists | default(false) \ No newline at end of file + when: not authorized_key_exists | default(false)