From 0107d7715239168e48c55173d9e81dd2cfb25fd0 Mon Sep 17 00:00:00 2001 From: yuncliu Date: Thu, 3 Dec 2020 16:32:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96playbook,=E4=BC=98=E5=8C=96se?= =?UTF-8?q?linux=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible.cfg | 1 + install.sh | 4 ++-- playbooks/CentOS_7.6_aarch64.yml | 36 +++++++++++++++++++--------- playbooks/CentOS_7.6_x86_64.yml | 36 +++++++++++++++++++--------- playbooks/install_nnae.yml | 4 ++-- playbooks/install_nnrt.yml | 4 ++-- playbooks/install_npu.yml | 7 ++++-- playbooks/install_python375.yml | 20 ++++++++++++---- playbooks/install_tfplugin.yml | 4 ++-- playbooks/install_toolbox.yml | 4 ++-- playbooks/task_driver.yml | 8 +++---- playbooks/task_firmware.yml | 4 ++-- playbooks/task_gcc.yml | 41 ++++++++++++++++++++++---------- 13 files changed, 116 insertions(+), 57 deletions(-) diff --git a/ansible.cfg b/ansible.cfg index f35e76bf..81b96992 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,4 +1,5 @@ [defaults] +command_warnings=False host_key_checking = false log_path=./install.log inventory=./inventory_file diff --git a/install.sh b/install.sh index fde13198..a71b0eed 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ function check_python375() echo "Warning: no python3.7.5 installed" return ${FALSE} fi - module_list="ctypes bz2 sqlite3 lzma" + module_list="ctypes sqlite3 lzma" for module in ${module_list} do have_no_python_module ${module} @@ -98,8 +98,8 @@ function process_install() ping_all echo "ansible-playbook -i ./inventory_file playbooks/gather_npu_fact.yml -e hosts_name=ascend" ansible-playbook -i ./inventory_file playbooks/gather_npu_fact.yml -e "hosts_name=ascend" - echo "ansible-playbook -i ./inventory_file playbooks/distribution.yml -e hosts_name=ascend" if [ "x${nocopy_flag}" != "xy" ];then + echo "ansible-playbook -i ./inventory_file playbooks/distribution.yml -e hosts_name=ascend" ansible-playbook -i ./inventory_file playbooks/distribution.yml -e "hosts_name=ascend" fi debug_cmd="" diff --git a/playbooks/CentOS_7.6_aarch64.yml b/playbooks/CentOS_7.6_aarch64.yml index e7d2150d..dfe4fd3d 100644 --- a/playbooks/CentOS_7.6_aarch64.yml +++ b/playbooks/CentOS_7.6_aarch64.yml @@ -1,18 +1,32 @@ -- name: mkdir resources - shell: mkdir -p ~/libselinux +- name: check if python have selinux module + shell: "{{ discovered_interpreter_python }} -c \"import selinux\"" + register: have_selinux + failed_when: false + changed_when: have_selinux.rc != 0 -- name: scp libpython-selinux +- name: create libselinux directory + file: + path: ~/libselinux + state: directory + recurse: yes + when: have_selinux.rc != 0 + +- name: scp libselinux-python to remote shell: /usr/bin/sshpass -p "{{ansible_ssh_pass}}" scp -o StrictHostKeyChecking=no ../resources/{{os_and_arch}}/libselinux*.rpm {{ansible_ssh_user}}@{{ansible_default_ipv4.address}}:~/libselinux delegate_to: localhost - when: inventory_hostname != "localhost" + when: + - inventory_hostname != "localhost" + - have_selinux.rc != 0 -- name: cp libpython-selinux for localhost +- name: cp libselinux-python to localhost shell: cp -f ../resources/{{os_and_arch}}/libselinux*.rpm ~/libselinux delegate_to: localhost - when: inventory_hostname == "localhost" - -- name: rm libselinux-devel - shell: rm -f ~/libselinux/libselinux-devel* + when: + - inventory_hostname == "localhost" + - have_selinux.rc != 0 -- name: install libpython-selinux - shell: rpm -ivh --force --nodeps ~/libselinux/libselinux*.rpm +# Usually the libselinux in the repository is newer than system +# so here add --replacepkgs +- name: install libselinux-python + shell: rpm -ivh --force --replacepkgs --nodeps ~/libselinux/libselinux*.rpm + when: have_selinux.rc != 0 diff --git a/playbooks/CentOS_7.6_x86_64.yml b/playbooks/CentOS_7.6_x86_64.yml index e7d2150d..dfe4fd3d 100644 --- a/playbooks/CentOS_7.6_x86_64.yml +++ b/playbooks/CentOS_7.6_x86_64.yml @@ -1,18 +1,32 @@ -- name: mkdir resources - shell: mkdir -p ~/libselinux +- name: check if python have selinux module + shell: "{{ discovered_interpreter_python }} -c \"import selinux\"" + register: have_selinux + failed_when: false + changed_when: have_selinux.rc != 0 -- name: scp libpython-selinux +- name: create libselinux directory + file: + path: ~/libselinux + state: directory + recurse: yes + when: have_selinux.rc != 0 + +- name: scp libselinux-python to remote shell: /usr/bin/sshpass -p "{{ansible_ssh_pass}}" scp -o StrictHostKeyChecking=no ../resources/{{os_and_arch}}/libselinux*.rpm {{ansible_ssh_user}}@{{ansible_default_ipv4.address}}:~/libselinux delegate_to: localhost - when: inventory_hostname != "localhost" + when: + - inventory_hostname != "localhost" + - have_selinux.rc != 0 -- name: cp libpython-selinux for localhost +- name: cp libselinux-python to localhost shell: cp -f ../resources/{{os_and_arch}}/libselinux*.rpm ~/libselinux delegate_to: localhost - when: inventory_hostname == "localhost" - -- name: rm libselinux-devel - shell: rm -f ~/libselinux/libselinux-devel* + when: + - inventory_hostname == "localhost" + - have_selinux.rc != 0 -- name: install libpython-selinux - shell: rpm -ivh --force --nodeps ~/libselinux/libselinux*.rpm +# Usually the libselinux in the repository is newer than system +# so here add --replacepkgs +- name: install libselinux-python + shell: rpm -ivh --force --replacepkgs --nodeps ~/libselinux/libselinux*.rpm + when: have_selinux.rc != 0 diff --git a/playbooks/install_nnae.yml b/playbooks/install_nnae.yml index b6e9afa4..2ed88a19 100644 --- a/playbooks/install_nnae.yml +++ b/playbooks/install_nnae.yml @@ -9,13 +9,13 @@ patterns: ".*nnae.*{{ ansible_architecture }}.run" register: nnae - - name: add run permission for {{ nnae.files[0].path }} + - name: add run permission for nnae file: path: "{{ nnae.files[0].path }}" mode: a+x when: nnae.matched > 0 - - name: install nnae {{ nnae.files[0].path }} + - name: install nnae shell: "{{ nnae.files[0].path }} --install --quiet --install-username={{ user }} --install-usergroup={{ group }}" register: nnae_result when: nnae.matched > 0 diff --git a/playbooks/install_nnrt.yml b/playbooks/install_nnrt.yml index b799ffe5..06ba7a76 100644 --- a/playbooks/install_nnrt.yml +++ b/playbooks/install_nnrt.yml @@ -9,13 +9,13 @@ patterns: ".*nnrt.*{{ ansible_architecture }}.run" register: nnrt - - name: add run permission for {{ nnrt.files[0].path }} + - name: add run permission for nnrt file: path: "{{ nnrt.files[0].path }}" mode: a+x when: nnrt.matched > 0 - - name: install nnrt {{ nnrt.files[0].path }} + - name: install nnrt shell: "{{ nnrt.files[0].path }} --install --quiet --install-username={{ user }} --install-usergroup={{ group }}" register: nnrt_result when: nnrt.matched > 0 diff --git a/playbooks/install_npu.yml b/playbooks/install_npu.yml index ec55f7e5..2e4ed74a 100644 --- a/playbooks/install_npu.yml +++ b/playbooks/install_npu.yml @@ -4,10 +4,13 @@ temp: "{{ ansible_distribution_version | regex_findall('[0-9]+.[0-9]+') }}" os_version: "{{ temp[0] }}" tasks: - - name: test driver exist + # check the driver, always success + # set changed when npu-smi info not work + - name: check if driver is already installed shell: npu-smi info register: smi_info - ignore_errors: yes + failed_when: false + changed_when: smi_info.rc != 0 - debug: var: smi_info diff --git a/playbooks/install_python375.yml b/playbooks/install_python375.yml index f2d354d0..d3fcc1c9 100644 --- a/playbooks/install_python375.yml +++ b/playbooks/install_python375.yml @@ -1,12 +1,22 @@ - hosts: '{{ hosts_name }}' tasks: - - name: mkdir build directory - shell: mkdir -p ~/build + - name: create build directory + file: + path: ~/build + state: directory + recurse: yes + - name: install python3.7.5 unarchive - shell: tar -xvf {{ resources_dir }}/Python-3.7.5.tar.xz -C ~/build + unarchive: + src: "{{ resources_dir }}/Python-3.7.5.tar.xz" + dest: ~/build + copy: no + - name: install python3.7.5 config shell: cd ~/build/Python-3.7.5; ./configure --enable-shared --prefix=/usr/local/python3.7.5 + - name: install python3.7.5 make - shell: cd ~/build/Python-3.7.5; make -j4 + shell: make -C ~/build/Python-3.7.5 -j4 + - name: install python3.7.5 make install - shell: cd ~/build/Python-3.7.5; make install + shell: make -C ~/build/Python-3.7.5 install diff --git a/playbooks/install_tfplugin.yml b/playbooks/install_tfplugin.yml index e6fe9cd0..5ed208ae 100644 --- a/playbooks/install_tfplugin.yml +++ b/playbooks/install_tfplugin.yml @@ -9,13 +9,13 @@ patterns: ".*tfplugin.*{{ansible_architecture}}.run" register: tfplugin - - name: add run permission for {{ tfplugin.files[0].path }} + - name: add run permission for tfplugin file: path: "{{ tfplugin.files[0].path }}" mode: a+x when: tfplugin.matched > 0 - - name: install tfplugin {{ tfplugin.files[0].path }} + - name: install tfplugin shell: "{{ tfplugin.files[0].path }} --install --quiet --install-username={{ user }} --install-usergroup={{ group }}" environment: LD_LIBRARY_PATH: /usr/local/python3.7.5/lib diff --git a/playbooks/install_toolbox.yml b/playbooks/install_toolbox.yml index a127686b..2c60390c 100644 --- a/playbooks/install_toolbox.yml +++ b/playbooks/install_toolbox.yml @@ -9,13 +9,13 @@ patterns: ".*toolbox.*{{ ansible_architecture }}.run" register: toolbox - - name: add run permission for {{ toolbox.files[0].path }} + - name: add run permission for toolbox file: path: "{{ toolbox.files[0].path }}" mode: a+x when: toolbox.matched > 0 - - name: install toolbox {{ toolbox.files[0].path }} + - name: install toolbox shell: "{{ toolbox.files[0].path }} --install --quiet --install-username={{ user }} --install-usergroup={{ group }}" register: toolbox_result when: toolbox.matched > 0 diff --git a/playbooks/task_driver.yml b/playbooks/task_driver.yml index 31168660..5794bfdc 100644 --- a/playbooks/task_driver.yml +++ b/playbooks/task_driver.yml @@ -36,25 +36,25 @@ var: driver_pkg verbosity: 1 -- name: add run permission for {{ driver_pkg.files[0].path }} +- name: add run permission for driver package file: path: "{{driver_pkg.files[0].path}}" mode: a+x when: driver_pkg.matched > 0 -- name: add run permission for {{ driver_pkg_linux.files[0].path }} +- name: add run permission for common linux driver package file: path: "{{driver_pkg_linux.files[0].path}}" mode: a+x when: driver_pkg.matched == 0 and driver_pkg_linux.matched > 0 -- name: install driver {{ driver_pkg.files[0].path }} +- name: install driver for specific os shell: "{{driver_pkg.files[0].path}} --full --quiet --install-username={{user}} --install-usergroup={{group}}" register: driver_result failed_when: "'install success' not in driver_result.stdout" when: driver_pkg.matched > 0 -- name: install driver common linux {{ driver_pkg_linux.files[0].path }} +- name: install driver for common linux shell: "{{driver_pkg_linux.files[0].path}} --full --quiet --install-username={{user}} --install-usergroup={{group}}" register: driver_result failed_when: "'install success' not in driver_result.stdout" diff --git a/playbooks/task_firmware.yml b/playbooks/task_firmware.yml index adb73496..9f33acf5 100644 --- a/playbooks/task_firmware.yml +++ b/playbooks/task_firmware.yml @@ -11,13 +11,13 @@ var: firmware_pkg verbosity: 1 -- name: add run permission for {{ firmware_pkg.files[0].path }} +- name: add run permission for firmware file: path: "{{ firmware_pkg.files[0].path }}" mode: a+x when: firmware_pkg.matched > 0 -- name: install firmware {{ firmware_pkg.files[0].path }} +- name: install firmware shell: "{{ firmware_pkg.files[0].path }} --full --quiet" register: firmware_result when: firmware_pkg.matched > 0 diff --git a/playbooks/task_gcc.yml b/playbooks/task_gcc.yml index 1b08823d..2f64f42b 100644 --- a/playbooks/task_gcc.yml +++ b/playbooks/task_gcc.yml @@ -1,33 +1,50 @@ -- name: mkdir - shell: "mkdir -p ~/build" +- name: create build directory + file: + path: ~/build + state: directory + recurse: yes - name: uncompress gcc - shell: "tar -xvf {{ resources_dir }}/gcc-7.3.0.tar.gz -C ~/build" + unarchive: + src: "{{ resources_dir }}/gcc-7.3.0.tar.gz" + dest: ~/build + copy: no - name: cp mpfr-3.1.4.tar.bz2 - shell: "cp {{ resources_dir }}/mpfr-3.1.4.tar.bz2 ~/build/gcc-7.3.0/" + copy: + src: "{{ resources_dir }}/mpfr-3.1.4.tar.bz2" + dest: ~/build/gcc-7.3.0/ + remote_src: yes - name: cp mpc-1.0.3.tar.gz - shell: "cp {{ resources_dir }}/mpc-1.0.3.tar.gz ~/build/gcc-7.3.0/" + copy: + src: "{{ resources_dir }}/mpc-1.0.3.tar.gz" + dest: ~/build/gcc-7.3.0/ + remote_src: yes - name: cp gmp-6.1.0.tar.bz2 - shell: "cp {{ resources_dir }}/gmp-6.1.0.tar.bz2 ~/build/gcc-7.3.0/" + copy: + src: "{{ resources_dir }}/gmp-6.1.0.tar.bz2" + dest: ~/build/gcc-7.3.0/ + remote_src: yes - name: cp isl-0.16.1.tar.bz2 - shell: "cp {{ resources_dir }}/isl-0.16.1.tar.bz2 ~/build/gcc-7.3.0/" + copy: + src: "{{ resources_dir }}/isl-0.16.1.tar.bz2" + dest: ~/build/gcc-7.3.0/ + remote_src: yes - name: download_prerequisites shell: cd ~/build/gcc-7.3.0/; ./contrib/download_prerequisites - name: check makefile exist stat: - path: "~/build/gcc-7.3.0/Makefile" + path: ~/build/gcc-7.3.0/Makefile register: makefile_stat - name: make distclean - shell: "cd ~/build/gcc-7.3.0; make distclean" + shell: make -C ~/build/gcc-7.3.0 distclean when: makefile_stat.stat.exists - register: configure_result - name: configure gcc shell: "cd ~/build/gcc-7.3.0; ./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/gcc7.3.0" @@ -38,13 +55,13 @@ register: cxx - name: make gcc - shell: "cd ~/build/gcc-7.3.0; make -j20" + shell: make -C ~/build/gcc-7.3.0 -j20 register: make_result when: "'0' in cxx.stdout" ignore_errors: yes - name: make install - shell: "cd ~/build/gcc-7.3.0; make install" + shell: make -C ~/build/gcc-7.3.0 install when: "'0' in cxx.stdout" register: install_result -- Gitee