|
| 1 | +--- |
| 2 | +- name: Include tacacs_passkey |
| 3 | + block: |
| 4 | + - name: Get inventory folder name |
| 5 | + set_fact: inv_file="{{ playbook_dir }}/group_vars/{{ inventory_file.split("/")[-1] }}/{{ inventory_file.split("/")[-1] }}.yml" |
| 6 | + |
| 7 | + - debug: msg="inv_file {{ inv_file }}" |
| 8 | + |
| 9 | + - name: Check inventory file exist |
| 10 | + stat: |
| 11 | + path: "{{ inv_file }}" |
| 12 | + register: inventory_file |
| 13 | + |
| 14 | + - name: Include tacacs_passkey from inventory file |
| 15 | + include_vars: "{{ inv_file }}" |
| 16 | + when: inventory_file.stat.exists |
| 17 | + |
| 18 | + - name: Include default tacacs_passkey |
| 19 | + include_vars: "{{ playbook_dir }}/group_vars/lab/lab.yml" |
| 20 | + when: tacacs_passkey is not defined |
| 21 | + |
| 22 | + when: tacacs_passkey is not defined |
| 23 | + |
| 24 | +- debug: msg="tacacs_passkey {{ tacacs_passkey }}" |
| 25 | + |
| 26 | +- name: Set ptf host |
| 27 | + set_fact: |
| 28 | + ptf_host: "ptf_{{ vm_set_name }}" |
| 29 | + |
| 30 | +- debug: msg="ptf_host {{ ptf_host }}" |
| 31 | + |
| 32 | +- name: Include duthost user name |
| 33 | + block: |
| 34 | + - name: Set duthost user name |
| 35 | + set_fact: |
| 36 | + dut_host_user: "{{ secret_group_vars['str']['ansible_ssh_user'] }}" |
| 37 | + |
| 38 | + when: |
| 39 | + - secret_group_vars is defined |
| 40 | + - secret_group_vars['str'] is defined |
| 41 | + - secret_group_vars['str']['ansible_ssh_user'] is defined |
| 42 | + |
| 43 | + - name: Set default duthost user name from group_vars/lab/secrets.yml |
| 44 | + block: |
| 45 | + - name: Include sonicadmin_user from group_vars/lab/secrets.yml |
| 46 | + include_vars: "{{ playbook_dir }}/group_vars/lab/secrets.yml" |
| 47 | + |
| 48 | + - name: Set dut user name |
| 49 | + set_fact: |
| 50 | + dut_host_user: "{{ sonicadmin_user }}" |
| 51 | + |
| 52 | + when: |
| 53 | + - dut_host_user is not defined |
| 54 | + |
| 55 | +- debug: msg="dut_host_user {{ dut_host_user }}" |
| 56 | + |
| 57 | +- name: Include duthost password |
| 58 | + block: |
| 59 | + - name: Encrypt encrypted_sonic_password from secret_group_vars |
| 60 | + block: |
| 61 | + |
| 62 | + - name: Encrypt TACACS password from secret_group_vars |
| 63 | + shell: python3 -c "import crypt; print(crypt.crypt('{{secret_group_vars['str']['altpasswords'][0]}}', 'abc'))" |
| 64 | + register: encrypted_sonic_password |
| 65 | + delegate_to: "{{ ptf_host }}" |
| 66 | + |
| 67 | + when: |
| 68 | + - secret_group_vars is defined |
| 69 | + - secret_group_vars['str'] is defined |
| 70 | + - secret_group_vars['str']['altpasswords'] is defined |
| 71 | + |
| 72 | + - name: Encrypt default encrypted_sonic_password from group_vars/lab/secrets.yml |
| 73 | + block: |
| 74 | + - name: Include sonicadmin_password from group_vars/lab/secrets.yml |
| 75 | + include_vars: "{{ playbook_dir }}/group_vars/lab/secrets.yml" |
| 76 | + |
| 77 | + - name: Encrypt TACACS password from sonicadmin_password |
| 78 | + shell: python3 -c "import crypt; print(crypt.crypt('{{sonicadmin_password}}', 'abc'))" |
| 79 | + register: encrypted_sonic_password |
| 80 | + delegate_to: "{{ ptf_host }}" |
| 81 | + |
| 82 | + when: |
| 83 | + - tacacs_user_passwd is not defined |
| 84 | + |
| 85 | + - name: Set TACACS password from encrypted_sonic_password |
| 86 | + set_fact: |
| 87 | + tacacs_user_passwd: '{{ encrypted_sonic_password.stdout }}' |
| 88 | + |
| 89 | +- debug: msg="tacacs_user_passwd {{ tacacs_user_passwd }}" |
| 90 | + |
| 91 | +- block: |
| 92 | + - name: Generate tacacs daily daemon config file |
| 93 | + template: |
| 94 | + src: tac_plus_daily.conf.j2 |
| 95 | + dest: /etc/tac_plus_daily.conf |
| 96 | + delegate_to: "{{ ptf_host }}" |
| 97 | + |
| 98 | + - name: Upload tacacs daily daemon file |
| 99 | + copy: |
| 100 | + src: 'scripts/tacacs_daily_daemon' |
| 101 | + dest: /root/tacacs_daily_daemon |
| 102 | + mode: "0755" |
| 103 | + delegate_to: "{{ ptf_host }}" |
| 104 | + |
| 105 | + - name: Upload tacacs daily start script |
| 106 | + copy: |
| 107 | + src: 'scripts/start_tacacs.sh' |
| 108 | + dest: /root/start_tacacs.sh |
| 109 | + mode: "0755" |
| 110 | + delegate_to: "{{ ptf_host }}" |
| 111 | + |
| 112 | + - name: Start tacacs daily daemon |
| 113 | + shell: /root/start_tacacs.sh |
| 114 | + delegate_to: "{{ptf_host}}" |
0 commit comments