Add an "accept_hostkey" parameter to the git module to help automatically

accept hostkeys for git repos and prevent task hangs when the key is unknown
reviewable/pr18780/r1
James Tanner 11 years ago
parent 7fbe046708
commit 24eba74edd

@ -43,6 +43,12 @@ options:
- What version of the repository to check out. This can be the - What version of the repository to check out. This can be the
full 40-character I(SHA-1) hash, the literal string C(HEAD), a full 40-character I(SHA-1) hash, the literal string C(HEAD), a
branch name, or a tag name. branch name, or a tag name.
accept_hostkey:
required: false
default: true
version_added: "1.5"
description:
- Add the hostkey for the repo url if not already added.
reference: reference:
required: false required: false
default: null default: null
@ -118,6 +124,7 @@ EXAMPLES = '''
import re import re
import tempfile import tempfile
def get_version(git_path, dest, ref="HEAD"): def get_version(git_path, dest, ref="HEAD"):
''' samples the version of the git repo ''' ''' samples the version of the git repo '''
os.chdir(dest) os.chdir(dest)
@ -352,6 +359,7 @@ def main():
force=dict(default='yes', type='bool'), force=dict(default='yes', type='bool'),
depth=dict(default=None, type='int'), depth=dict(default=None, type='int'),
update=dict(default='yes', type='bool'), update=dict(default='yes', type='bool'),
accept_hostkey=dict(default='yes', type='bool'),
executable=dict(default=None), executable=dict(default=None),
bare=dict(default='no', type='bool'), bare=dict(default='no', type='bool'),
), ),
@ -369,6 +377,10 @@ def main():
reference = module.params['reference'] reference = module.params['reference']
git_path = module.params['executable'] or module.get_bin_path('git', True) git_path = module.params['executable'] or module.get_bin_path('git', True)
# add the git repo's hostkey
if module.params['accept_hostkey']:
add_git_host_key(module, repo, accept_hostkey=True)
if bare: if bare:
gitconfig = os.path.join(dest, 'config') gitconfig = os.path.join(dest, 'config')
else: else:
@ -430,4 +442,6 @@ def main():
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.known_hosts import *
main() main()

Loading…
Cancel
Save