[[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.SHDescription: Files: Store the source file and configuration files that need to be synchronized to the remote server; handlers: the action to be taken when the resource changes, if no such directory can not be built or empty; Meta: role definitions can be left blank; Tasks:python the installation process into a task that needs to be performed; templates: template file used to execute Python installation, generally script; VARs: The variable defined in this installation can not be built python3 if it is not necessary.6. 6 Source Code Storage directory: Python_install/files/python-3.6.6. tgz specific Operations1. Create a Python role file to invoke Python_install[[email protected]:/etc/ansible]#Cat/etc/ansible/python.yml----hosts:all remote_user:root roles:-Python_install2. Create a task file [[email protected]:/etc/ansible/roles]#Catpython_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.SHDest=/tmp/python_install.SHOwner=root Group=root mode=755[email protected]:/etc/ansible/roles]#Catpython_install/tasks/Install. Yml-Name:Installpython Shell:/bin/bash/tmp/python_install.SH[email protected]:/etc/ansible/roles]#Catpython_install/tasks/main.yml-include:copy.yml-Include:Install. YML Note: a.copy If you copy a directory, you need to add a recursive parameter, recurse; b.copy If you copy the directory, no directory will be created on the target server; c.copy If you copy the file to a directory on the target server, you need to add the Dest parameter to the /usr/local/src/, not/usr/local/.SRC, otherwise ansible will copy the file as src instead of the SRC directory. 4writing template scripts [[email protected]:/etc/ansible/roles]#CatPython_install/templates/python_install.SH #!/bin/bash#InstallPython3.6.6# YumToolsYum-Y Groupinstall"Development Tools"Yum-YInstallZlib-develbzip2-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/Python3 Make&& Make InstallLN-s/usr/local/python3/bin/python3/usr/bin/Python3LN-s/usr/local/python3/bin/pip3/usr/bin/pip3# End Installation script feature:1) Install the Yum dependency package2Create a directory, unzip the file, and compile and install to the target directory3generate a soft connection to perform the playbook test [[email protected]:/etc/ansible]# Ansible-playbook-C python.yml execution [[email protected]:/etc/ansible]# Ansible-playbook python.yml
Ansible Batch compilation installation with Shell script python3.6.6