From 2eae709acd76c57bed84a7e466f60460175957da Mon Sep 17 00:00:00 2001 From: David Lopez Date: Thu, 27 Jul 2023 07:23:49 +0000 Subject: [PATCH] Update create_user_ssh/check_authorizzed_key.yml --- create_user_ssh/check_authorizzed_key.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/create_user_ssh/check_authorizzed_key.yml b/create_user_ssh/check_authorizzed_key.yml index e69de29..0b99059 100644 --- a/create_user_ssh/check_authorizzed_key.yml +++ b/create_user_ssh/check_authorizzed_key.yml @@ -0,0 +1,19 @@ +--- +- name: Check Authorized Key Existence + hosts: "{{ hosts}} + gather_facts: yes + + tasks: + - name: Read authorized_keys file + shell: cat ~/.ssh/authorized_keys + register: authorized_keys_output + ignore_errors: yes + + - name: Check if authorized key exists + set_fact: + authorized_key_exists: "{{ lookup('search', 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDHFG9s2iWDwiBTHmczwtXnH276FfAY5ehCmMkB6KMIrKl38DHxEWY3ajHUdnXsN7kL9EGmh4cKMaW3MYtDTFVAFs3dzupyJuOMbSV3KWXn5dcOfmV4m6IxjV8fyVQSF7xEmD/vXFxJOzY7wJnYMnAGD1RCqVx7r6XefCqHoXLm2LQ/IcIjFiBa3QeSW8KZ5wdHdoGtFYJFrPipr7RZ/ByU144AWyaxEloEdYwzOmzY2BOLsmst+Q8GBa8CCDiTnehLp/4Jxpvz5pByaIpqCh1od4Wpi+01id0FlKOPPvzu6GvkkQ5Vp3Eq2KvnDQENN6/rgnbvozs0JpjsLNKfb2x5Bkgjts3GYhdNWxEPpxCThtCzsRGUYb+XcRzG2ufmdYdq+nT+tPxOpI9MX2MnR+M/Z2u2aL8zWfEei73xg09UO5xgHPhW/hzyVHlLljO6qgAfZui/12FEUzbIBESNsoIc6mspvQcQhUdreaeFa8qlxqZ9rr5CmX+lRrnszbcHo9s0BmNUnt8BS79krHfJ0s/k8aCN0t+JPJF2yJNgxDGW9URS8kMfgHFbETsj0kZ87EueU6Opom9cy9QKxGa/hmm+WzO50EaQR6MEk2doc6J9tcVOnF0qAifCc+++89XBS7BmEiTa+WoV2/Znw/4ScmsxVjo6MKHB8cNR6q6CMMyLJw== rvalles@ubuntu1604', content) | bool }}" + when: authorized_keys_output.rc == 0 + + - name: Display result + debug: + msg: "Authorized key exists: {{ authorized_key_exists | default(false) }}"