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
7e8e186b
Commit
7e8e186b
authored
Oct 16, 2013
by
jctanner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4517 from adfinis-sygroup/devel
Remove keys regardless of the options
parents
c737f222
af704562
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
26 deletions
+27
-26
library/system/authorized_key
+27
-26
No files found.
library/system/authorized_key
View file @
7e8e186b
...
@@ -226,16 +226,17 @@ def readkeys(filename):
...
@@ -226,16 +226,17 @@ def readkeys(filename):
if
not
os
.
path
.
isfile
(
filename
):
if
not
os
.
path
.
isfile
(
filename
):
return
[]
return
[]
keys
=
[]
keys
=
{}
f
=
open
(
filename
)
f
=
open
(
filename
)
for
line
in
f
.
readlines
():
for
line
in
f
.
readlines
():
key_data
=
parsekey
(
line
)
key_data
=
parsekey
(
line
)
if
key_data
:
if
key_data
:
keys
.
append
(
key_data
)
# use key as identifier
keys
[
key_data
[
0
]]
=
key_data
else
:
else
:
# for an invalid line, just append the line
# for an invalid line, just append the line
# to the array so it will be re-output later
# to the array so it will be re-output later
keys
.
append
(
line
)
keys
[
line
]
=
line
f
.
close
()
f
.
close
()
return
keys
return
keys
...
@@ -244,16 +245,20 @@ def writekeys(module, filename, keys):
...
@@ -244,16 +245,20 @@ def writekeys(module, filename, keys):
fd
,
tmp_path
=
tempfile
.
mkstemp
(
''
,
'tmp'
,
os
.
path
.
dirname
(
filename
))
fd
,
tmp_path
=
tempfile
.
mkstemp
(
''
,
'tmp'
,
os
.
path
.
dirname
(
filename
))
f
=
open
(
tmp_path
,
"w"
)
f
=
open
(
tmp_path
,
"w"
)
try
:
try
:
for
key
in
keys
:
for
index
,
key
in
keys
.
items
()
:
try
:
try
:
(
keyhash
,
type
,
options
,
comment
)
=
key
(
keyhash
,
type
,
options
,
comment
)
=
key
option_str
=
""
option_str
=
""
if
options
:
if
options
:
option_strings
=
[]
for
option_key
in
options
.
keys
():
for
option_key
in
options
.
keys
():
if
options
[
option_key
]:
if
options
[
option_key
]:
option_str
+=
"
%
s=
%
s "
%
(
option_key
,
options
[
option_key
]
)
option_str
ings
.
append
(
"
%
s=
%
s"
%
(
option_key
,
options
[
option_key
])
)
else
:
else
:
option_str
+=
"
%
s "
%
option_key
option_strings
.
append
(
"
%
s "
%
option_key
)
option_str
=
","
.
join
(
option_strings
)
option_str
+=
" "
key_line
=
"
%
s
%
s
%
s
%
s
\n
"
%
(
option_str
,
type
,
keyhash
,
comment
)
key_line
=
"
%
s
%
s
%
s
%
s
\n
"
%
(
option_str
,
type
,
keyhash
,
comment
)
except
:
except
:
key_line
=
key
key_line
=
key
...
@@ -295,39 +300,35 @@ def enforce_state(module, params):
...
@@ -295,39 +300,35 @@ def enforce_state(module, params):
present
=
False
present
=
False
matched
=
False
matched
=
False
non_matching_keys
=
[]
non_matching_keys
=
[]
for
existing_key
in
existing_keys
:
# skip bad entries or bad input
if
parsed_new_key
[
0
]
in
existing_keys
:
if
len
(
parsed_new_key
)
==
0
or
len
(
existing_key
)
==
0
:
present
=
True
continue
# Then we check if everything matches, including
# the first element in the array after parsing
# the key type and options. If not, we append this
# is the actual key hash, which we check first
# existing key to the non-matching list
if
parsed_new_key
[
0
]
==
existing_key
[
0
]:
# We only want it to match everything when the state
present
=
True
# is present
# Then we check if everything matches, including
if
parsed_new_key
!=
existing_keys
[
parsed_new_key
[
0
]]
and
state
==
"present"
:
# the key type and options. If not, we append this
non_matching_keys
.
append
(
existing_keys
[
parsed_new_key
[
0
]])
# existing key to the non-matching list
else
:
if
parsed_new_key
!=
existing_key
:
matched
=
True
non_matching_keys
.
append
(
existing_key
)
else
:
matched
=
True
# handle idempotent state=present
# handle idempotent state=present
if
state
==
"present"
:
if
state
==
"present"
:
if
unique
and
len
(
non_matching_keys
)
>
0
:
if
unique
and
len
(
non_matching_keys
)
>
0
:
for
non_matching_key
in
non_matching_keys
:
for
non_matching_key
in
non_matching_keys
:
existing_keys
.
remove
(
non_matching_key
)
del
existing_keys
[
non_matching_key
[
0
]]
do_write
=
True
do_write
=
True
if
not
matched
:
if
not
matched
:
existing_keys
.
append
(
parsed_new_key
)
existing_keys
[
parsed_new_key
[
0
]]
=
parsed_new_key
do_write
=
True
do_write
=
True
elif
state
==
"absent"
:
elif
state
==
"absent"
:
# currently, we only remove keys when
# they are an exact match
if
not
matched
:
if
not
matched
:
continue
continue
existing_keys
.
remove
(
parsed_new_key
)
del
existing_keys
[
parsed_new_key
[
0
]]
do_write
=
True
do_write
=
True
if
do_write
:
if
do_write
:
...
...
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