summaryrefslogtreecommitdiff
path: root/test/integration/targets/cs_sshkeypair/tasks/main.yml
blob: 0d3f3f7546c6a144a2b0d15ed0d592ef2bfa9b25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
- name: setup cleanup
  cs_sshkeypair: name={{ cs_resource_prefix }}-sshkey state=absent

- name: test fail on missing name
  action: cs_sshkeypair
  ignore_errors: true
  register: sshkey
- name: verify results of fail on missing name
  assert:
    that:
    - sshkey|failed
    - "sshkey.msg == 'missing required arguments: name'"

- name: test ssh key creation
  cs_sshkeypair: name={{ cs_resource_prefix }}-sshkey
  register: sshkey
- name: verify results of ssh key creation
  assert:
    that:
    - sshkey|success
    - sshkey|changed
    - sshkey.fingerprint is defined and sshkey.fingerprint != ""
    - sshkey.private_key is defined and sshkey.private_key != ""
    - sshkey.name == "{{ cs_resource_prefix }}-sshkey"

- name: test ssh key creation idempotence
  cs_sshkeypair: name={{ cs_resource_prefix }}-sshkey
  register: sshkey2
- name: verify results of ssh key creation idempotence
  assert:
    that:
    - sshkey2|success
    - not sshkey2|changed
    - sshkey2.fingerprint is defined and sshkey2.fingerprint == sshkey.fingerprint
    - sshkey2.private_key is not defined
    - sshkey2.name == "{{ cs_resource_prefix }}-sshkey"

- name: test replace ssh public key
  cs_sshkeypair: |
    name={{ cs_resource_prefix }}-sshkey
    public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsTI7KJZ8tz/CwQIrSol41c6s3vzkGYCMI8o7P9Et48UG9eRoGaMaGYaTvBTj/VQrD7cfurI6Bn0HTT3FLK3OHOweyelm9rIiQ2hjkSl+2lIKWHu992GO58E5Gcy9yYW4sHGgGLNZkPBKrrj0w7lhmiHjPtVnf+2+7Ix1WOO2/HXPcAHhsX/AlyItDewIL4mr/BT83vq0202sPCiM2cFQJl+5WGwS1wYYK8d167cspsmdyX7OyAFCUB0vueuqjE8MFqJvyIJR9y8Lj9Ny71pSV5/QWrXUgELxMYOKSby3gHkxcIXgYBMFLl4DipRTO74OWQlRRaOlqXlOOQbikcY4T rene.moser@swisstxt.ch"
  register: sshkey3
- name: verify results of replace ssh public key
  assert:
    that:
    - sshkey3|success
    - sshkey3|changed
    - sshkey3.fingerprint is defined and sshkey3.fingerprint != sshkey2.fingerprint
    - sshkey3.private_key is not defined
    - sshkey3.name == "{{ cs_resource_prefix }}-sshkey"

- name: test replace ssh public key idempotence
  cs_sshkeypair: |
    name={{ cs_resource_prefix }}-sshkey
    public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsTI7KJZ8tz/CwQIrSol41c6s3vzkGYCMI8o7P9Et48UG9eRoGaMaGYaTvBTj/VQrD7cfurI6Bn0HTT3FLK3OHOweyelm9rIiQ2hjkSl+2lIKWHu992GO58E5Gcy9yYW4sHGgGLNZkPBKrrj0w7lhmiHjPtVnf+2+7Ix1WOO2/HXPcAHhsX/AlyItDewIL4mr/BT83vq0202sPCiM2cFQJl+5WGwS1wYYK8d167cspsmdyX7OyAFCUB0vueuqjE8MFqJvyIJR9y8Lj9Ny71pSV5/QWrXUgELxMYOKSby3gHkxcIXgYBMFLl4DipRTO74OWQlRRaOlqXlOOQbikcY4T rene.moser@swisstxt.ch"
  register: sshkey4
- name: verify results of ssh public key idempotence
  assert:
    that:
    - sshkey4|success
    - not sshkey4|changed
    - sshkey4.fingerprint is defined and sshkey4.fingerprint == sshkey3.fingerprint
    - sshkey4.private_key is not defined
    - sshkey4.name == "{{ cs_resource_prefix }}-sshkey"

- name: test ssh key absent
  cs_sshkeypair: name={{ cs_resource_prefix }}-sshkey state=absent
  register: sshkey5
- name: verify result of key absent
  assert:
    that:
    - sshkey5|success
    - sshkey5|changed
    - sshkey5.fingerprint is defined and sshkey5.fingerprint == sshkey3.fingerprint
    - sshkey5.private_key is not defined
    - sshkey5.name == "{{ cs_resource_prefix }}-sshkey"

- name: test ssh key absent idempotence
  cs_sshkeypair: name={{ cs_resource_prefix }}-sshkey state=absent
  register: sshkey6
- name: verify result of ssh key absent idempotence
  assert:
    that:
    - sshkey6|success
    - not sshkey6|changed
    - sshkey6.fingerprint is not defined
    - sshkey6.private_key is not defined
    - sshkey6.name is not defined