Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
b698f7a4
Commit
b698f7a4
authored
Mar 30, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to create host_key directory if it doesn't exist
Fixes #6731
parent
6e809c2b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
lib/ansible/module_utils/known_hosts.py
+12
-4
No files found.
lib/ansible/module_utils/known_hosts.py
View file @
b698f7a4
...
...
@@ -30,7 +30,7 @@ import hmac
from
hashlib
import
sha1
HASHED_KEY_MAGIC
=
"|1|"
def
add_git_host_key
(
module
,
url
,
accept_hostkey
=
True
):
def
add_git_host_key
(
module
,
url
,
accept_hostkey
=
True
,
create_dir
=
True
):
""" idempotently add a git url hostkey """
...
...
@@ -40,7 +40,7 @@ def add_git_host_key(module, url, accept_hostkey=True):
known_host
=
check_hostkey
(
module
,
fqdn
)
if
not
known_host
:
if
accept_hostkey
:
rc
,
out
,
err
=
add_host_key
(
module
,
fqdn
)
rc
,
out
,
err
=
add_host_key
(
module
,
fqdn
,
create_dir
=
create_dir
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
"failed to add
%
s hostkey:
%
s"
%
(
fqdn
,
out
+
err
))
else
:
...
...
@@ -120,7 +120,7 @@ def not_in_host_file(self, host):
return
True
def
add_host_key
(
module
,
fqdn
,
key_type
=
"rsa"
):
def
add_host_key
(
module
,
fqdn
,
key_type
=
"rsa"
,
create_dir
=
False
):
""" use ssh-keyscan to add the hostkey """
...
...
@@ -136,7 +136,15 @@ def add_host_key(module, fqdn, key_type="rsa"):
user_ssh_dir
=
os
.
path
.
expanduser
(
user_ssh_dir
)
if
not
os
.
path
.
exists
(
user_ssh_dir
):
module
.
fail_json
(
msg
=
"
%
s does not exist"
%
user_ssh_dir
)
if
create_dir
:
try
:
os
.
makedirs
(
user_ssh_dir
,
0700
)
except
:
module
.
fail_json
(
msg
=
"failed to create host key directory:
%
s"
%
user_ssh_dir
)
else
:
module
.
fail_json
(
msg
=
"
%
s does not exist"
%
user_ssh_dir
)
elif
not
os
.
path
.
isdir
(
user_ssh_dir
):
module
.
fail_json
(
msg
=
"
%
s is not a directory"
%
user_ssh_dir
)
this_cmd
=
"
%
s -t
%
s
%
s"
%
(
keyscan_cmd
,
key_type
,
fqdn
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment