From aaa6efd4bff2c43ce008d39243a9ae8a3de74056 Mon Sep 17 00:00:00 2001 From: fumingwei Date: Tue, 25 May 2021 12:25:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Estage2=20provision=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roles/certstore/tasks/main.yml | 2 +- .../roles/firewall/tasks/main.yml | 6 +- tsg-9140-scripts/roles/mrzcpd/tasks/main.yml | 2 +- tsg-9140-scripts/roles/sapp/tasks/main.yml | 4 +- .../roles/telegraf_statistic/tasks/main.yml | 2 +- tsg-9140-scripts/roles/tfe/tasks/main.yml | 4 +- .../files/tsg-os-provision-convertor.service | 15 +++ .../files/tsg-os-provision.service | 14 +++ .../files/tsg-os-provision/hosts | 2 + .../files/tsg-os-provision/provision.sh | 9 ++ .../tsg-os-provision/provision.yml.sample | 32 +++++++ .../tsg-os-provision/tasks/provision.yml | 92 +++++++++++++++++++ .../files/tsg-os-provision/templates/.gitkeep | 0 .../roles/tsg-os-provision/tasks/main.yml | 12 +++ tsg-9140-scripts/tsg_9140_deploy.yml | 2 +- 15 files changed, 187 insertions(+), 11 deletions(-) create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision-convertor.service create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision.service create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/hosts create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.sh create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.yml.sample create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/tasks/provision.yml create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/templates/.gitkeep create mode 100644 tsg-9140-scripts/roles/tsg-os-provision/tasks/main.yml diff --git a/tsg-9140-scripts/roles/certstore/tasks/main.yml b/tsg-9140-scripts/roles/certstore/tasks/main.yml index 4a9b62f9..07d94f65 100644 --- a/tsg-9140-scripts/roles/certstore/tasks/main.yml +++ b/tsg-9140-scripts/roles/certstore/tasks/main.yml @@ -12,7 +12,7 @@ - name: template certstore configure file template: src: "{{ role_path }}/templates/cert_store.ini.j2.j2" - dest: /opt/tsg/init_runtime/templates/cert_store.ini.j2 + dest: /opt/tsg/tsg-os-provision/templates/cert_store.ini.j2 - name: template certstore zlog file template: diff --git a/tsg-9140-scripts/roles/firewall/tasks/main.yml b/tsg-9140-scripts/roles/firewall/tasks/main.yml index 1aad7a2c..5db6f263 100644 --- a/tsg-9140-scripts/roles/firewall/tasks/main.yml +++ b/tsg-9140-scripts/roles/firewall/tasks/main.yml @@ -9,20 +9,20 @@ - name: "Template the tsgconf/main.conf" template: src: "{{ role_path }}/templates/main.conf.j2.j2" - dest: /opt/tsg/init_runtime/templates/main.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/main.conf.j2 tags: template - name: "Template the tsgconf/maat.conf" template: src: "{{ role_path }}/templates/maat.conf.j2.j2" - dest: /opt/tsg/init_runtime/templates/maat.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/maat.conf.j2 tags: template - name: "Template the conf/capture_packet_plug.conf.j2" template: src: "{{ role_path }}/templates/capture_packet_plug.conf.j2.j2" - dest: /opt/tsg/init_runtime/templates/capture_packet_plug.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/capture_packet_plug.conf.j2 tags: template - name: "Template the /home/mesasoft/sapp_run/plug/business/tsg_conn_sketch/tsg_conn_sketch.inf" diff --git a/tsg-9140-scripts/roles/mrzcpd/tasks/main.yml b/tsg-9140-scripts/roles/mrzcpd/tasks/main.yml index 16a08c52..3177aff7 100644 --- a/tsg-9140-scripts/roles/mrzcpd/tasks/main.yml +++ b/tsg-9140-scripts/roles/mrzcpd/tasks/main.yml @@ -13,7 +13,7 @@ - name: "update mrglobal.conf - TSG9140" template: src: "{{ role_path }}/templates/tsg_9140/mrglobal.conf.tsg_9140.j2.j2" - dest: /opt/tsg/init_runtime/templates/mrglobal.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/mrglobal.conf.j2 ##################### mrzcpd ##################### - name: "enable mrenv" diff --git a/tsg-9140-scripts/roles/sapp/tasks/main.yml b/tsg-9140-scripts/roles/sapp/tasks/main.yml index d7b948b1..d4c4a855 100644 --- a/tsg-9140-scripts/roles/sapp/tasks/main.yml +++ b/tsg-9140-scripts/roles/sapp/tasks/main.yml @@ -25,7 +25,7 @@ - name: Template the sapp.toml template: src: "{{ role_path }}/templates/sapp.toml.j2.j2" - dest: /opt/tsg/init_runtime/templates/sapp.toml.j2 + dest: /opt/tsg/tsg-os-provision/templates/sapp.toml.j2 tags: template - name: Template the project_list.conf @@ -85,7 +85,7 @@ - name: Template the gdev.conf template: src: "{{ role_path }}/templates/gdev.conf.j2.j2" - dest: /opt/tsg/init_runtime/templates/gdev.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/gdev.conf.j2 tags: template - name: "sapp: service adapts runtimes" diff --git a/tsg-9140-scripts/roles/telegraf_statistic/tasks/main.yml b/tsg-9140-scripts/roles/telegraf_statistic/tasks/main.yml index e2fb67b0..8c8ec0f5 100644 --- a/tsg-9140-scripts/roles/telegraf_statistic/tasks/main.yml +++ b/tsg-9140-scripts/roles/telegraf_statistic/tasks/main.yml @@ -12,7 +12,7 @@ - name: "Templates telegraf.conf" template: src: "{{role_path}}/templates/telegraf_statistic.conf.j2.j2" - dest: /opt/tsg/init_runtime/templates/telegraf_statistic.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/telegraf_statistic.conf.j2 tags: template - name: "copy telegraf_statistic.service to destination server" diff --git a/tsg-9140-scripts/roles/tfe/tasks/main.yml b/tsg-9140-scripts/roles/tfe/tasks/main.yml index b2351a8b..959816b3 100644 --- a/tsg-9140-scripts/roles/tfe/tasks/main.yml +++ b/tsg-9140-scripts/roles/tfe/tasks/main.yml @@ -30,7 +30,7 @@ - name: "template the tfe.conf" template: src: "{{ role_path }}/templates/tfe.conf.j2.j2" - dest: /opt/tsg/init_runtime/templates/tfe.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/tfe.conf.j2 - name: "template the zlog.conf" template: @@ -45,7 +45,7 @@ - name: "template the pangu_pxy.conf" template: src: "{{ role_path }}/templates/pangu_pxy.conf.j2.j2" - dest: /opt/tsg/init_runtime/templates/pangu_pxy.conf.j2 + dest: /opt/tsg/tsg-os-provision/templates/pangu_pxy.conf.j2 - name: "create conf/doh/" file: diff --git a/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision-convertor.service b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision-convertor.service new file mode 100644 index 00000000..e11a773e --- /dev/null +++ b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision-convertor.service @@ -0,0 +1,15 @@ +[Unit] +Description=tsg os provision convertor +Requires=network.target +After=network.target +Before=tsg-os-provision.service + +[Service] +ExecStart=/bin/sh -c "echo \'provision-convertor start\'" +ExecStop=/bin/sh -c "echo \'provision-convertor stop\'" +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +RequiredBy=tsg-os-provision.service \ No newline at end of file diff --git a/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision.service b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision.service new file mode 100644 index 00000000..bc54116d --- /dev/null +++ b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision.service @@ -0,0 +1,14 @@ +[Unit] +Description=Tsg os provision +Requires=network.target tsg-os-provision-convertor.service +After=network.target sg-os-provision-convertor.service +Before=tfe-env.service mrenv.service + +[Service] +ExecStart=/bin/sh -c "/opt/tsg/tsg-os-provison/provision.sh" +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +RequiredBy=tfe-env.service mrenv.service diff --git a/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/hosts b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/hosts new file mode 100644 index 00000000..71c3838e --- /dev/null +++ b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/hosts @@ -0,0 +1,2 @@ +[provision] +localhost ansible_connection=local \ No newline at end of file diff --git a/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.sh b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.sh new file mode 100644 index 00000000..14d57ce4 --- /dev/null +++ b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +config_path=/data/tsg-os-provision/provision.yml +backup_config_path=/data/tsg-os-provision/provision.yml.bak +hosts_path=/opt/tsg/tsg-os-provision/hosts +provision_path=/opt/tsg/tsg-os-provision/tasks/provision.yml + +ansible-playbook -i ${hosts_path} ${provision_path} -e "var_files_path=${config_path}" +cp /data/tsg-os-provision/provision.yml /data/tsg-os-provision/provision.yml.bak -r \ No newline at end of file diff --git a/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.yml.sample b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.yml.sample new file mode 100644 index 00000000..be037921 --- /dev/null +++ b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/provision.yml.sample @@ -0,0 +1,32 @@ +maat_redis_server: + address: "192.168.100.1" + port: 7002 + port_num: 1 + db: 0 + +dynamic_maat_redis_server: + address: "192.168.100.1" + port: 7002 + port_num: 1 + db: 1 + +breakpad_upload_url: http://10.4.63.4:9000/api/2/minidump/?sentry_key=3203b43fd5384a7dbe6a48ecb1f3c595 +data_center: Kyzylorda +tsg_master_entrance_id: 9 + + +log_kafkabrokers: + address: ['1.1.1.1:9092','2.2.2.2:9092'] + + +firewall: + hos_serverip: "192.168.40.223" + hos_serverport: 9098 + APP_SKETCH_PUBLISH_TOPIC: "APP_SIGNATURE_ID" + APP_SKETCH_BROKER_LIST: "tcp://192.168.40.161:1883" + + +pangu_pxy: + log_cache: + address: "10.9.62.253" + port: 9090 \ No newline at end of file diff --git a/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/tasks/provision.yml b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/tasks/provision.yml new file mode 100644 index 00000000..a51ed46d --- /dev/null +++ b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/tasks/provision.yml @@ -0,0 +1,92 @@ +--- +- hosts: provision + vars_files: + - '{{var_files_path}}' + tasks: + - name: "tsg-os-provision: obtain result_exec_obtain_keepalive_subnet" + shell: ipmitool picmg addrinfo | grep "Hardware Address" | sed 's/^Hardware Address.*0x4\(.*\)/\1/' | awk '{print strtonum("0x"$1)+16'} + register: result_exec_obtain_keepalive_subnet + + - name: "tsg-os-provision: output results that executes command that gets the result_exec_obtain_keepalive_subnet" + debug: + msg: "{{ result_exec_obtain_keepalive_subnet }}" + + - name: "tsg-os-provision: check result_exec_obtain_keepalive_subnet" + assert: + that: + - result_exec_obtain_keepalive_subnet.rc == 0 + - result_exec_obtain_keepalive_subnet.failed == False + - result_exec_obtain_keepalive_subnet.stdout_lines | length == 1 + - result_exec_obtain_keepalive_subnet.stdout_lines[0] | int >= 16 + - result_exec_obtain_keepalive_subnet.stdout_lines[0] | int <= 31 + fail_msg: "error:{{ result_exec_obtain_keepalive_subnet.stderr }},stdout:{{ result_exec_obtain_keepalive_subnet.stdout_lines }}" + success_msg: "{{ result_exec_obtain_keepalive_subnet.stdout_lines[0] }}" + + - name: "tsg-os-provision: Set fact for field keepalive_subnet_ip" + set_fact: + keepalive_subnet_ip: "{{ result_exec_obtain_keepalive_subnet.stdout_lines[0] }}" + + - name: "tsg-os-provision: template gdev.conf file" + template: + src: "../templates/gdev.conf.j2" + dest: /home/mesasoft/sapp_run/etc/gdev.conf + tags: sapp + + - name: "tsg-os-provision: template mrglobal.conf file" + template: + src: "../templates/mrglobal.conf.j2" + dest: /opt/mrzcpd/etc/mrglobal.conf + tags: mrzcpd + + - name: "tsg-os-provision: template certstore configure file" + template: + src: "../templates/cert_store.ini.j2" + dest: /opt/tsg/certstore/conf/cert_store.ini + tags: certstore + + - name: "tsg-os-provision: Template the tsgconf/main.conf" + template: + src: "../templates/main.conf.j2" + dest: /home/mesasoft/sapp_run/tsgconf/main.conf + tags: firewall + + - name: "tsg-os-provision: Template the tsgconf/maat.conf" + template: + src: "../templates/maat.conf.j2" + dest: /home/mesasoft/sapp_run/tsgconf/maat.conf + tags: firewall + + - name: "tsg-os-provision: Template the conf/capture_packet_plug.conf" + template: + src: "../templates/capture_packet_plug.conf.j2" + dest: /home/mesasoft/sapp_run/conf/capture_packet_plug.conf + tags: firewall + + - name: "tsg-os-provision: Template the sapp.toml" + template: + src: "../templates/sapp.toml.j2" + dest: /home/mesasoft/sapp_run/etc/sapp.toml + tags: sapp + + - name: "tsg-os-provision: Templates telegraf.conf" + template: + src: "../templates/telegraf_statistic.conf.j2" + dest: /etc/telegraf/telegraf_statistic.conf + tags: telegraf_statistic + + - name: "tsg-os-provision: template the tfe.conf" + template: + src: "../templates/tfe.conf.j2" + dest: /opt/tsg/tfe/conf/tfe/tfe.conf + tags: tfe + + - name: "tsg-os-provision: template the pangu_pxy.conf" + template: + src: "../templates/pangu_pxy.conf.j2" + dest: /opt/tsg/tfe/conf/pangu/pangu_pxy.conf + tags: tfe + + - name: "tsg-os-provision: snapshot the stage2 config files" + copy: + src: /data/tsg-os-provision/provision.yml + dest: /data/tsg-os-provision/provision.yml.snapshot diff --git a/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/templates/.gitkeep b/tsg-9140-scripts/roles/tsg-os-provision/files/tsg-os-provision/templates/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tsg-9140-scripts/roles/tsg-os-provision/tasks/main.yml b/tsg-9140-scripts/roles/tsg-os-provision/tasks/main.yml new file mode 100644 index 00000000..c7a8c92d --- /dev/null +++ b/tsg-9140-scripts/roles/tsg-os-provision/tasks/main.yml @@ -0,0 +1,12 @@ +- name: "tsg-os-provision: copy tsg-os-provision scripts to dest" + copy: + src: "{{ role_path }}/files/tsg-os-provision" + dest: /opt/tsg/ + mode: 0644 + +- name: "tsg-os-provision: chmod 0755 for provison.sh" + file: + path: "{{ item }}" + mode: '0755' + with_items: + - /opt/tsg/tsg-os-provision/provision.sh diff --git a/tsg-9140-scripts/tsg_9140_deploy.yml b/tsg-9140-scripts/tsg_9140_deploy.yml index 712a34c4..2350c226 100644 --- a/tsg-9140-scripts/tsg_9140_deploy.yml +++ b/tsg-9140-scripts/tsg_9140_deploy.yml @@ -5,7 +5,7 @@ - install_config/group_vars/rpm_version.yml roles: #- {role: init-env, tags: init-env} - - {role: init_runtime, tags: init_runtime} + - {role: tsg-os-provision, tags: tsg-os-provision} - {role: framework, tags: framework} #- {role: kernel-ml, tags: kernel-ml} - {role: mrzcpd, tags: mrzcpd}