diff --git a/ansible/roles/tsg_sn/files/cmm_api_tst b/ansible/roles/tsg_sn/files/cmm_api_tst new file mode 100644 index 00000000..a228f128 Binary files /dev/null and b/ansible/roles/tsg_sn/files/cmm_api_tst differ diff --git a/ansible/roles/tsg_sn/files/tsg7400_obtain_sn_from_mxn.sh b/ansible/roles/tsg_sn/files/tsg7400_obtain_sn_from_mxn.sh new file mode 100644 index 00000000..09bed603 --- /dev/null +++ b/ansible/roles/tsg_sn/files/tsg7400_obtain_sn_from_mxn.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [ ! -f "/opt/tsg/tsg-os-provision/cmm_api_tst" ];then + echo "not found cmm_api_tst!" + exit 1 +fi + +/opt/tsg/tsg-os-provision/cmm_api_tst 9 1 1 127.0.0.1 | tee chid.id +if [ $? != 0 ]; then + echo "cmm_api_tst failed!" + exit 1 +fi + +CHID=`cat chid.id | sed -n '1p' | awk -F ":" '{print $2}' | sed 's/ //g'` +CHIDL=`echo $CHID | awk '{print length($0)}'` + +if [ $CHIDL != 20 ];then + echo "CHID length is not 20!" + exit 1 +fi + +echo "{\"sn\": \"$CHID\"}" > /opt/tsg/etc/tsg_sn.json diff --git a/ansible/roles/tsg_sn/tasks/main.yml b/ansible/roles/tsg_sn/tasks/main.yml index 708daad1..f39d909f 100644 --- a/ansible/roles/tsg_sn/tasks/main.yml +++ b/ansible/roles/tsg_sn/tasks/main.yml @@ -3,4 +3,15 @@ template: src: "{{ role_path }}/templates/tsg_sn.json.j2.j2" dest: /opt/tsg/tsg-os-provision/templates/tsg_sn.json.j2 - tags: template \ No newline at end of file + tags: template + when: PROFILE_ID == '9000-NPB-P01R01' + +- name: "Template the tsg_sn.json.j2.j2" + copy: + src: "{{ item }}" + dest: /opt/tsg/tsg-os-provision/ + mode: 0755 + with_items: + - "{{ role_path }}/files/tsg7400_obtain_sn_from_mxn.sh" + - "{{ role_path }}/files/cmm_api_tst" + when: PROFILE_ID == '7400-MCN0-P01R01' or PROFILE_ID == '7400-MCN123-P01R01' \ No newline at end of file diff --git a/ansible/tsg_7400_deploy.yml b/ansible/tsg_7400_deploy.yml index 329aa26c..3eeef6a9 100644 --- a/ansible/tsg_7400_deploy.yml +++ b/ansible/tsg_7400_deploy.yml @@ -7,6 +7,7 @@ - {role: tsg-os-provision, tags: tsg-os-provision} - {role: system-init, tags: system-init} - {role: system-init-7400-mcn0, tags: system-init-7400-mcn0} + - {role: tsg_sn, tags: tsg_sn} - {role: tsg-diagnose, tags: tsg-diagnose} - hosts: 7400-MCN123-P01R01 @@ -17,4 +18,5 @@ roles: - {role: tsg-os-provision, tags: tsg-os-provision} - {role: system-init, tags: system-init} - - {role: system-init-7400-mcn123, tags: system-init-7400-mcn123} \ No newline at end of file + - {role: system-init-7400-mcn123, tags: system-init-7400-mcn123} + - {role: tsg_sn, tags: tsg_sn} \ No newline at end of file