mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-25 05:23:58 -07:00 
			
		
		
		
	[PR #10011/c2480730 backport][stable-9] fix: github_deploy_key check key exists on 422 (#10035)
fix: github_deploy_key check key exists on 422 (#10011)
* fix: github_deploy_key check key exists on 422
If we get a 422 response code as we add a key, check if it's because the key already exists or for another reason.
fixes: #6718
* chore: add changelog 10011-github_deploy_key-check-key-present
* chore: fix changelog fragment
* chore: fix changelog fragment
* Update changelog fragment.
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c248073079)
Co-authored-by: Alex Garel <alex@garel.org>
	
	
This commit is contained in:
		
					parent
					
						
							
								8b1a193a49
							
						
					
				
			
			
				commit
				
					
						2448503e8b
					
				
			
		
					 2 changed files with 8 additions and 1 deletions
				
			
		|  | @ -0,0 +1,2 @@ | |||
| bugfixes: | ||||
|   - "github_deploy_key - check that key really exists on 422 to avoid masking other errors (https://github.com/ansible-collections/community.general/issues/6718, https://github.com/ansible-collections/community.general/pull/10011)." | ||||
|  | @ -259,7 +259,12 @@ class GithubDeployKey(object): | |||
|             key_id = response_body["id"] | ||||
|             self.module.exit_json(changed=True, msg="Deploy key successfully added", id=key_id) | ||||
|         elif status_code == 422: | ||||
|             self.module.exit_json(changed=False, msg="Deploy key already exists") | ||||
|             # there might be multiple reasons for a 422 | ||||
|             # so we must check if the reason is that the key already exists | ||||
|             if self.get_existing_key(): | ||||
|                 self.module.exit_json(changed=False, msg="Deploy key already exists") | ||||
|             else: | ||||
|                 self.handle_error(method="POST", info=info) | ||||
|         else: | ||||
|             self.handle_error(method="POST", info=info) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue