forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_ptf_password.yml
More file actions
63 lines (52 loc) · 1.79 KB
/
Copy pathupdate_ptf_password.yml
File metadata and controls
63 lines (52 loc) · 1.79 KB
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
- include_vars:
file: "{{ playbook_dir }}/group_vars/ptf/secrets.yml"
name: raw_ptf_secrets
no_log: true
- name: Render ptf secrets
set_fact:
ptf_secrets: >-
{{
dict(
raw_ptf_secrets.keys() | zip(raw_ptf_secrets.values()
)
)
}}
no_log: true
- block:
- name: Init default ptf_username
set_fact:
ptf_username: "root"
when: ptf_username is not defined
- name: Init default ptf_password
set_fact:
ptf_password: "root"
when: ptf_password is not defined
no_log: true
- name: Override default ptf_username
set_fact:
ptf_username: "{{ ptf_secrets['ansible_user'] }}"
when: "'ansible_user' in ptf_secrets"
- name: Override default ptf_password
set_fact:
ptf_password: "{{ ptf_secrets['ansible_ssh_pass'] }}"
when: "'ansible_ssh_pass' in ptf_secrets"
- name: Get ptf_alt_passwords from ptf_secrets
set_fact:
ptf_alt_passwords: "{{ ptf_secrets['ansible_altpasswords'] }}"
no_log: true
- name: If ptf_alt_passwords is a list, set ptf_password to its first value
set_fact:
ptf_password: "{{ ptf_alt_passwords[0] }}"
when: ptf_alt_passwords | type_debug == "list" and ptf_alt_passwords | length > 0
no_log: true
- name: If ptf_alt_passwords is not a list, log a debug message
debug:
msg: >-
The 'ansible_altpasswords' field in group_vars/ptf/secrets.yml is not a list.
Falling back to use the 'ansible_ssh_pass' field."
when: ptf_alt_passwords | type_debug != "list"
- name: Update ptf username and password
command: docker exec -t ptf_{{ vm_set_name }} sh -c 'echo "{{ ptf_username }}:{{ ptf_password }}" | chpasswd'
become: yes
no_log: true
when: ptf_secrets is defined and 'ansible_altpasswords' in ptf_secrets