ansible配合shell指令碼批量編譯安裝python3.6.6

來源:互聯網
上載者:User

標籤:角色   編寫   OLE   group   hosts   指令碼批量   指令碼   handler   一個   

[[email protected]:/etc]# tree /etc/ansible//etc/ansible/├── ansible.cfg├── hosts├── python.yml└── roles    └── python_install        ├── files        │   └── Python-3.6.6.tgz        ├── tasks        │   ├── copy.yml        │   ├── install.yml        │   └── main.yml        └── templates            └── python_install.sh說明: files:存放需要同步到異地伺服器的源碼檔案及設定檔; handlers:當資源發生變化時需要進行的操作,若沒有此目錄可以不建或為空白; meta:角色定義可留空; tasks:python安裝過程成需要進行的執行的任務; templates:用於執行python安裝的模板檔案,一般為指令碼; vars:本次安裝定義的變數,若無必要可以不建python3.6.6源碼存放目錄:python_install/files/Python-3.6.6.tgz具體操作1.建立python角色檔案,用於調用python_install[[email protected]:/etc/ansible]# cat /etc/ansible/python.yml ---- hosts: all  remote_user: root  roles:    - python_install2.建立任務檔案[[email protected]:/etc/ansible/roles]# cat python_install/tasks/copy.yml - name: copy python_tgz to client  copy: src=/etc/ansible/roles/python_install/files/Python-3.6.6.tgz dest=/usr/local/src/- name: copy install_python_script to client  copy: src=/etc/ansible/roles/python_install/templates/python_install.sh dest=/tmp/python_install.sh owner=root group=root mode=755[[email protected]:/etc/ansible/roles]# cat python_install/tasks/install.yml - name: install python  shell: /bin/bash /tmp/python_install.sh[[email protected]:/etc/ansible/roles]# cat python_install/tasks/main.yml - include: copy.yml- include: install.yml注意: a.copy如果複製目錄,需要加上遞迴參數,recurse; b.copy如果複製目錄,沒有目錄將會在目標伺服器上建立; c.copy如果複製檔案到目標伺服器的某一個目錄下,需要在dest參數上加上/usr/local/src/,而不是/usr/local/src,否則ansible將會把檔案複製為src,而不是放在src目錄下。 4.編寫模板指令碼[[email protected]:/etc/ansible/roles]# cat python_install/templates/python_install.sh #!/bin/bash# install python3.6.6# yum toolsyum -y groupinstall "Development tools"yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-develcd /usr/local/srcmkdir /usr/local/python3tar -zxf Python-3.6.6.tgzcd Python-3.6.6./configure --prefix=/usr/local/python3make && make installln -s /usr/local/python3/bin/python3 /usr/bin/python3ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3# end安裝指令碼功能: 1)安裝yum依賴包2)建立目錄,解壓檔案並編譯安裝到目標目錄3)產生軟串連執行playbook測試[[email protected]:/etc/ansible]# ansible-playbook -C python.yml 執行[[email protected]:/etc/ansible]# ansible-playbook python.yml 

 

ansible配合shell指令碼批量編譯安裝python3.6.6

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.