2014-04-02 19:25:24 +00:00
|
|
|
# test code for the authorized_key module
|
|
|
|
# (c) 2014, James Cammarata <jcammarata@ansible.com>
|
|
|
|
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# Setup steps
|
|
|
|
|
|
|
|
- name: touch the authorized_keys file
|
|
|
|
file: dest="{{output_dir}}/authorized_keys" state=touch
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the authorized_keys file was created
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.state == "file"'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# basic ssh-dss key
|
|
|
|
|
|
|
|
- name: add basic ssh-dss key
|
|
|
|
authorized_key: user=root key="{{ dss_key_basic }}" state=present path="{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the key was added
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.key == dss_key_basic'
|
|
|
|
- 'result.key_options == None'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
- name: re-add basic ssh-dss key
|
|
|
|
authorized_key: user=root key="{{ dss_key_basic }}" state=present path="{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that nothing changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == False'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# ssh-dss key with an unquoted option
|
|
|
|
|
|
|
|
- name: add ssh-dss key with an unquoted option
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_unquoted_option }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the key was added
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.key == dss_key_unquoted_option'
|
|
|
|
- 'result.key_options == None'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
- name: re-add ssh-dss key with an unquoted option
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_unquoted_option }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that nothing changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == False'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# ssh-dss key with a leading command="/bin/foo"
|
|
|
|
|
|
|
|
- name: add ssh-dss key with a leading command
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_command }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the key was added
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.key == dss_key_command'
|
|
|
|
- 'result.key_options == None'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
- name: re-add ssh-dss key with a leading command
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_command }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that nothing changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == False'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# ssh-dss key with a complex quoted leading command
|
|
|
|
# ie. command="/bin/echo foo 'bar baz'"
|
|
|
|
|
|
|
|
- name: add ssh-dss key with a complex quoted leading command
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_complex_command }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the key was added
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.key == dss_key_complex_command'
|
|
|
|
- 'result.key_options == None'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
- name: re-add ssh-dss key with a complex quoted leading command
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_complex_command }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that nothing changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == False'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# ssh-dss key with a command and a single option, which are
|
|
|
|
# in a comma-separated list
|
|
|
|
|
|
|
|
- name: add ssh-dss key with a command and a single option
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_command_single_option }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the key was added
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.key == dss_key_command_single_option'
|
|
|
|
- 'result.key_options == None'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
- name: re-add ssh-dss key with a command and a single option
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_command_single_option }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that nothing changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == False'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# ssh-dss key with a command and multiple other options
|
|
|
|
|
|
|
|
- name: add ssh-dss key with a command and multiple options
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_command_multiple_options }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the key was added
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.key == dss_key_command_multiple_options'
|
|
|
|
- 'result.key_options == None'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
- name: re-add ssh-dss key with a command and multiple options
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_command_multiple_options }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that nothing changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == False'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
# ssh-dss key with multiple trailing parts, which are space-
|
|
|
|
# separated and not quoted in any way
|
|
|
|
|
|
|
|
- name: add ssh-dss key with trailing parts
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_trailing }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the key was added
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == True'
|
|
|
|
- 'result.key == dss_key_trailing'
|
|
|
|
- 'result.key_options == None'
|
2014-04-02 19:25:24 +00:00
|
|
|
|
|
|
|
- name: re-add ssh-dss key with trailing parts
|
|
|
|
authorized_key:
|
|
|
|
user: root
|
|
|
|
key: "{{ dss_key_trailing }}"
|
|
|
|
state: present
|
|
|
|
path: "{{output_dir|expanduser}}/authorized_keys"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that nothing changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-07-10 05:53:59 +00:00
|
|
|
- 'result.changed == False'
|
2014-04-02 19:25:24 +00:00
|
|
|
|