PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/test/integration/roles/test_authorized_key/tasks/main.yml

https://github.com/ajanthanm/ansible
YAML | 244 lines | 168 code | 41 blank | 35 comment | 0 complexity | 745e03e78316b689dbbaa3eddbc58c8e MD5 | raw file
  1# test code for the authorized_key module
  2# (c) 2014, James Cammarata <jcammarata@ansible.com>
  3
  4# This file is part of Ansible
  5#
  6# Ansible is free software: you can redistribute it and/or modify
  7# it under the terms of the GNU General Public License as published by
  8# the Free Software Foundation, either version 3 of the License, or
  9# (at your option) any later version.
 10#
 11# Ansible is distributed in the hope that it will be useful,
 12# but WITHOUT ANY WARRANTY; without even the implied warranty of
 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14# GNU General Public License for more details.
 15#
 16# You should have received a copy of the GNU General Public License
 17# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
 18
 19
 20# -------------------------------------------------------------
 21# Setup steps
 22
 23- name: touch the authorized_keys file
 24  file: dest="{{output_dir}}/authorized_keys" state=touch
 25  register: result
 26
 27- name: assert that the authorized_keys file was created
 28  assert:
 29    that:
 30    - ['result.changed == True']
 31    - ['result.state == "file"']
 32
 33# -------------------------------------------------------------
 34# basic ssh-dss key
 35
 36- name: add basic ssh-dss key
 37  authorized_key: user=root key="{{ dss_key_basic }}" state=present path="{{output_dir|expanduser}}/authorized_keys"
 38  register: result
 39
 40- name: assert that the key was added
 41  assert:
 42    that:
 43    - ['result.changed == True']
 44    - ['result.key == dss_key_basic']
 45    - ['result.key_options == None']
 46
 47- name: re-add basic ssh-dss key
 48  authorized_key: user=root key="{{ dss_key_basic }}" state=present path="{{output_dir|expanduser}}/authorized_keys"
 49  register: result
 50
 51- name: assert that nothing changed
 52  assert:
 53    that:
 54    - ['result.changed == False']
 55
 56# -------------------------------------------------------------
 57# ssh-dss key with an unquoted option
 58
 59- name: add ssh-dss key with an unquoted option
 60  authorized_key: 
 61    user: root
 62    key: "{{ dss_key_unquoted_option }}"
 63    state: present
 64    path: "{{output_dir|expanduser}}/authorized_keys"
 65  register: result
 66
 67- name: assert that the key was added
 68  assert:
 69    that:
 70    - ['result.changed == True']
 71    - ['result.key == dss_key_unquoted_option']
 72    - ['result.key_options == None']
 73
 74- name: re-add ssh-dss key with an unquoted option
 75  authorized_key:
 76    user: root
 77    key: "{{ dss_key_unquoted_option }}"
 78    state: present
 79    path: "{{output_dir|expanduser}}/authorized_keys"
 80  register: result
 81
 82- name: assert that nothing changed
 83  assert:
 84    that:
 85    - ['result.changed == False']
 86
 87# -------------------------------------------------------------
 88# ssh-dss key with a leading command="/bin/foo"
 89
 90- name: add ssh-dss key with a leading command
 91  authorized_key: 
 92    user: root
 93    key: "{{ dss_key_command }}"
 94    state: present
 95    path: "{{output_dir|expanduser}}/authorized_keys"
 96  register: result
 97
 98- name: assert that the key was added
 99  assert:
100    that:
101    - ['result.changed == True']
102    - ['result.key == dss_key_command']
103    - ['result.key_options == None']
104
105- name: re-add ssh-dss key with a leading command
106  authorized_key:
107    user: root
108    key: "{{ dss_key_command }}"
109    state: present
110    path: "{{output_dir|expanduser}}/authorized_keys"
111  register: result
112
113- name: assert that nothing changed
114  assert:
115    that:
116    - ['result.changed == False']
117
118# -------------------------------------------------------------
119# ssh-dss key with a complex quoted leading command
120# ie. command="/bin/echo foo 'bar baz'"
121
122- name: add ssh-dss key with a complex quoted leading command
123  authorized_key:
124    user: root
125    key: "{{ dss_key_complex_command }}"
126    state: present
127    path: "{{output_dir|expanduser}}/authorized_keys"
128  register: result
129
130- name: assert that the key was added
131  assert:
132    that:
133    - ['result.changed == True']
134    - ['result.key == dss_key_complex_command']
135    - ['result.key_options == None']
136
137- name: re-add ssh-dss key with a complex quoted leading command
138  authorized_key:
139    user: root
140    key: "{{ dss_key_complex_command }}"
141    state: present
142    path: "{{output_dir|expanduser}}/authorized_keys"
143  register: result
144
145- name: assert that nothing changed
146  assert:
147    that:
148    - ['result.changed == False']
149
150# -------------------------------------------------------------
151# ssh-dss key with a command and a single option, which are
152# in a comma-separated list
153
154- name: add ssh-dss key with a command and a single option
155  authorized_key:
156    user: root
157    key: "{{ dss_key_command_single_option }}"
158    state: present
159    path: "{{output_dir|expanduser}}/authorized_keys"
160  register: result
161
162- name: assert that the key was added
163  assert:
164    that:
165    - ['result.changed == True']
166    - ['result.key == dss_key_command_single_option']
167    - ['result.key_options == None']
168
169- name: re-add ssh-dss key with a command and a single option
170  authorized_key:
171    user: root
172    key: "{{ dss_key_command_single_option }}"
173    state: present
174    path: "{{output_dir|expanduser}}/authorized_keys"
175  register: result
176
177- name: assert that nothing changed
178  assert:
179    that:
180    - ['result.changed == False']
181
182# -------------------------------------------------------------
183# ssh-dss key with a command and multiple other options
184
185- name: add ssh-dss key with a command and multiple options
186  authorized_key:
187    user: root
188    key: "{{ dss_key_command_multiple_options }}"
189    state: present
190    path: "{{output_dir|expanduser}}/authorized_keys"
191  register: result
192
193- name: assert that the key was added
194  assert:
195    that:
196    - ['result.changed == True']
197    - ['result.key == dss_key_command_multiple_options']
198    - ['result.key_options == None']
199
200- name: re-add ssh-dss key with a command and multiple options
201  authorized_key:
202    user: root
203    key: "{{ dss_key_command_multiple_options }}"
204    state: present
205    path: "{{output_dir|expanduser}}/authorized_keys"
206  register: result
207
208- name: assert that nothing changed
209  assert:
210    that:
211    - ['result.changed == False']
212
213# -------------------------------------------------------------
214# ssh-dss key with multiple trailing parts, which are space-
215# separated and not quoted in any way
216
217- name: add ssh-dss key with trailing parts
218  authorized_key:
219    user: root
220    key: "{{ dss_key_trailing }}"
221    state: present
222    path: "{{output_dir|expanduser}}/authorized_keys"
223  register: result
224
225- name: assert that the key was added
226  assert:
227    that:
228    - ['result.changed == True']
229    - ['result.key == dss_key_trailing']
230    - ['result.key_options == None']
231
232- name: re-add ssh-dss key with trailing parts
233  authorized_key:
234    user: root
235    key: "{{ dss_key_trailing }}"
236    state: present
237    path: "{{output_dir|expanduser}}/authorized_keys"
238  register: result
239
240- name: assert that nothing changed
241  assert:
242    that:
243    - ['result.changed == False']
244