|
1 | 1 | ---
|
2 | 2 | - name: Install tools
|
3 | 3 | package:
|
4 |
| - name: |
5 |
| - - sshpass |
| 4 | + name: "{{ item }}" |
6 | 5 | state: present
|
| 6 | + ignore_errors: true |
| 7 | + loop: |
| 8 | + - sshpass |
| 9 | + - openssh |
| 10 | + - openssh-clients |
| 11 | + - openssh-server |
| 12 | + |
| 13 | +- name: Allow password Login for sshd |
| 14 | + ansible.builtin.lineinfile: |
| 15 | + path: /etc/ssh/sshd_config |
| 16 | + search_string: PasswordAuthentication no |
| 17 | + line: PasswordAuthentication yes |
| 18 | + when: |
| 19 | + - ansible_facts.distribution == "Amazon" |
| 20 | + |
| 21 | +- name: Start sshd service |
| 22 | + ansible.builtin.service: |
| 23 | + name: "{{ item }}" |
| 24 | + state: started |
| 25 | + ignore_errors: true |
| 26 | + loop: |
| 27 | + - sshd |
| 28 | + - ssh |
7 | 29 |
|
8 | 30 | - name: Set password for test
|
9 | 31 | ansible.builtin.set_fact:
|
|
16 | 38 |
|
17 | 39 | - name: Create ssh-client-keypair
|
18 | 40 | community.crypto.openssh_keypair:
|
19 |
| - path: /root/.ssh/locked_user_id |
| 41 | + path: /root/locked_user_id |
20 | 42 | type: ed25519
|
21 | 43 | state: present
|
22 | 44 | register: generated_key
|
|
29 | 51 |
|
30 | 52 | - name: Check successful login with password
|
31 | 53 | ansible.builtin.shell:
|
32 |
| - cmd: sshpass -p {{ test_pw }} ssh locked_user@localhost echo "success" |
| 54 | + cmd: sshpass -p {{ test_pw }} ssh -o StrictHostKeyChecking=no locked_user@localhost echo "success" |
33 | 55 |
|
34 | 56 | - name: Check successful login with ssh key
|
35 | 57 | ansible.builtin.shell:
|
36 |
| - cmd: ssh -i /root/.ssh/locked_user_id locked_user@localhost echo "success" |
| 58 | + cmd: ssh -i /root/locked_user_id -o StrictHostKeyChecking=no locked_user@localhost echo "success" |
37 | 59 |
|
38 | 60 | - name: Set password change date for locked_user
|
39 | 61 | ansible.builtin.shell:
|
40 | 62 | cmd: chage -d 2020-01-01 locked_user
|
41 | 63 |
|
42 | 64 | - name: Check unsuccessful login with password
|
43 | 65 | ansible.builtin.shell:
|
44 |
| - cmd: sshpass -p {{ test_pw }} ssh locked_user@localhost echo "success" |
| 66 | + cmd: sshpass -p {{ test_pw }} ssh -o StrictHostKeyChecking=no locked_user@localhost echo "success" |
45 | 67 | register: output
|
46 | 68 | ignore_errors: true
|
47 | 69 |
|
|
51 | 73 | - output.rc | int == 1
|
52 | 74 | - "'WARNING: Your password has expired.' in output.stderr"
|
53 | 75 | - "'success' not in output.stdout"
|
| 76 | + when: |
| 77 | + - ansible_facts.os_family != "OpenSuse" |
| 78 | + |
| 79 | +- name: Assert check unsuccessful login |
| 80 | + ansible.builtin.assert: |
| 81 | + that: |
| 82 | + - output.rc | int == 5 |
| 83 | + - output.stderr | length == 0 |
| 84 | + - output.stdout | length == 0 |
| 85 | + when: |
| 86 | + - ansible_facts.os_family == "OpenSuse" |
54 | 87 |
|
55 | 88 | - name: Check successful login with ssh key
|
56 | 89 | ansible.builtin.shell:
|
57 |
| - cmd: ssh -i /root/.ssh/locked_user_id locked_user@localhost echo "success" |
| 90 | + cmd: ssh -i /root/locked_user_id -o StrictHostKeyChecking=no locked_user@localhost echo "success" |
0 commit comments