|
10 | 10 | state: directory |
11 | 11 | loop: "{{ files }}" |
12 | 12 |
|
| 13 | +- name: Create parent directories for SSH |
| 14 | + ansible.builtin.file: |
| 15 | + path: "{{ ssh_profile.path }}" |
| 16 | + state: directory |
| 17 | + mode: "0700" |
| 18 | + |
| 19 | +- name: Check if combined_profiles.tgz exists |
| 20 | + ansible.builtin.stat: |
| 21 | + path: "{{ download_dir }}/combined_profiles.tgz" |
| 22 | + register: combined_profiles_stat |
| 23 | + |
13 | 24 | - name: Download and verify files |
14 | 25 | ansible.builtin.get_url: |
15 | 26 | url: "{{ item.url }}" |
16 | 27 | dest: "{{ download_dir }}/{{ item.parent }}/{{ item.dest }}" |
17 | 28 | checksum: "sha256:{{ item.sha256 }}" |
18 | 29 | loop: "{{ files }}" |
19 | 30 |
|
20 | | -- name: Generate SSH key pair (if applicable) |
21 | | - ansible.builtin.openssh_keypair: |
| 31 | +- name: Check if SSH private key already exists |
| 32 | + ansible.builtin.stat: |
22 | 33 | path: "{{ ssh_profile.path }}/id_rsa" |
23 | | - type: rsa |
24 | | - size: 2048 |
25 | | - when: ssh_profile.ssh_keypair | default(false) |
| 34 | + register: ssh_key_status |
| 35 | + |
| 36 | +- name: Generate SSH key pair using Bash (if not already present) |
| 37 | + ansible.builtin.command: > |
| 38 | + ssh-keygen -t rsa -b 2048 -f "{{ ssh_profile.path }}/id_rsa" -N "" |
| 39 | + when: not ssh_key_status.stat.exists |
26 | 40 |
|
27 | 41 | - name: Add public key to authorized_keys |
28 | 42 | ansible.builtin.copy: |
29 | 43 | content: "{{ lookup('file', ssh_profile.path + '/id_rsa.pub') }}" |
30 | 44 | dest: "{{ ssh_profile.path }}/authorized_keys" |
31 | | - when: ssh_profile.ssh_keypair | default(false) |
32 | 45 |
|
33 | 46 | - name: Create SSH config file |
34 | 47 | ansible.builtin.copy: |
|
38 | 51 | UserKnownHostsFile /dev/null |
39 | 52 | ForwardX11Trusted yes |
40 | 53 | dest: "{{ ssh_profile.path }}/config" |
41 | | - when: ssh_profile.ssh_keypair | default(false) |
42 | 54 |
|
43 | 55 | - name: Set permissions for SSH files |
44 | 56 | ansible.builtin.file: |
45 | 57 | path: "{{ ssh_profile.path }}/{{ item.file }}" |
46 | 58 | mode: "{{ item.mode }}" |
47 | 59 | loop: "{{ ssh_profile.permissions }}" |
48 | | - when: ssh_profile.ssh_keypair | default(false) |
49 | 60 |
|
50 | 61 | - name: Compress profiles into tarball |
51 | 62 | ansible.builtin.archive: |
52 | 63 | path: |
53 | 64 | - "{{ download_dir }}/profiles" |
54 | | - - "{{ ssh_profile.path }}" |
55 | 65 | dest: "{{ download_dir }}/combined_profiles.tgz" |
56 | 66 | format: gz |
| 67 | + when: not combined_profiles_stat.stat.exists |
| 68 | + |
| 69 | +- name: Set permissions for combined_profiles.tgz |
| 70 | + ansible.builtin.file: |
| 71 | + path: "{{ download_dir }}/combined_profiles.tgz" |
| 72 | + mode: "0666" |
| 73 | + when: combined_profiles_stat.stat.exists |
57 | 74 |
|
58 | 75 | - name: Clean up temporary files |
59 | 76 | ansible.builtin.file: |
|
0 commit comments