“Ansible基础”的版本间的差异
跳到导航
跳到搜索
(→分发文件) |
|||
第85行: | 第85行: | ||
[https://blog.csdn.net/reblue520/article/details/81301223 ansible配合shell脚本批量编译安装python3.6.6] | [https://blog.csdn.net/reblue520/article/details/81301223 ansible配合shell脚本批量编译安装python3.6.6] | ||
+ | |||
+ | |||
+ | =ansible配合shell脚本批量安装golang= | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
+ | == run== | ||
+ | <pre> | ||
+ | root@myxps:/etc/ansible# ansible-playbook -C go.yml | ||
+ | [WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly | ||
+ | calculated text widths that can cause Display to print incorrect line lengths | ||
+ | |||
+ | PLAY [all] ***************************************************************************************************** | ||
+ | |||
+ | TASK [Gathering Facts] ***************************************************************************************** | ||
+ | ok: [192.168.10.121] | ||
+ | ok: [192.168.10.120] | ||
+ | |||
+ | TASK [go_install : copy go_tgz to client] ********************************************************************** | ||
+ | changed: [192.168.10.120] | ||
+ | changed: [192.168.10.121] | ||
+ | |||
+ | TASK [go_install : copy install_go_script to client] *********************************************************** | ||
+ | changed: [192.168.10.120] | ||
+ | changed: [192.168.10.121] | ||
+ | |||
+ | TASK [go_install : install go] ********************************************************************************* | ||
+ | skipping: [192.168.10.120] | ||
+ | skipping: [192.168.10.121] | ||
+ | |||
+ | PLAY RECAP ***************************************************************************************************** | ||
+ | 192.168.10.120 : ok=3 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 | ||
+ | 192.168.10.121 : ok=3 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 | ||
+ | |||
+ | root@myxps:/etc/ansible# ansible-playbook go.yml | ||
+ | [WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line | ||
+ | lengths | ||
+ | |||
+ | PLAY [all] ****************************************************************************************************************************************************************** | ||
+ | |||
+ | TASK [Gathering Facts] ****************************************************************************************************************************************************** | ||
+ | ok: [192.168.10.121] | ||
+ | ok: [192.168.10.120] | ||
+ | |||
+ | TASK [go_install : copy go_tgz to client] *********************************************************************************************************************************** | ||
+ | changed: [192.168.10.120] | ||
+ | changed: [192.168.10.121] | ||
+ | |||
+ | TASK [go_install : copy install_go_script to client] ************************************************************************************************************************ | ||
+ | changed: [192.168.10.120] | ||
+ | changed: [192.168.10.121] | ||
+ | |||
+ | TASK [go_install : install go] ********************************************************************************************************************************************** | ||
+ | changed: [192.168.10.120] | ||
+ | changed: [192.168.10.121] | ||
+ | |||
+ | PLAY RECAP ****************************************************************************************************************************************************************** | ||
+ | 192.168.10.120 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 | ||
+ | 192.168.10.121 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 | ||
+ | |||
+ | |||
+ | </pre> | ||
=分发文件= | =分发文件= |
2021年9月23日 (四) 09:52的版本
目录
ins
#on master pip3 install --user ansible ssh-copy-id -i id_ecdsa.pub [email protected] ssh-copy-id -i id_ecdsa.pub [email protected] ssh-copy-id -i id_ecdsa.pub [email protected] mkdir /etc/ansible vi /etc/ansible/hosts 192.168.88.50 192.168.88.51 192.168.88.52 [intra] 192.168.10.120 192.168.10.121 ansible all -b -u root -a "hostname" 192.168.88.51 | CHANGED | rc=0 >> k8s-node1 192.168.88.50 | CHANGED | rc=0 >> k8s-master 192.168.88.52 | CHANGED | rc=0 >> k8s-node2 ansible all -m ping
配置文件
ansible在使用配置文件时按照以下顺序优先配置: export ANSIBLE_CONFIG ./ansible.cfg ~/.ansible.cfg /etc/ansible/ansible.cfg 如果以上顺序没有找到配置文件ansible会自动使用默认配置 可以去github上把默认配置拿下来: https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg # To generate an example config file (a "disabled" one with all default settings, commented out): # $ ansible-config init --disabled > ansible.cfg # Also you can now have a more complete file by including existing plugins: # ansible-config init --disabled -t all > ansible.cfg 把它放到/etc/ansible/目录
ansible配合shell脚本批量编译安装python3.7
https://github.com/evan886/my-ansible
具体安排脚本here https://github.com/evan886/my-ansible/tree/main/ansible4py3.7ins
git clone [email protected]:evan886/my-ansible.git cd ansible4py3.7ins/ 执行playbook 测试 root@myxps:/etc/ansible# ansible-playbook -C python.yml 执行 root@myxps:/etc/ansible# ansible-playbook python.yml
ansible配合shell脚本批量编译安装python3.6.6
ansible配合shell脚本批量安装golang
run
root@myxps:/etc/ansible# ansible-playbook -C go.yml [WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths PLAY [all] ***************************************************************************************************** TASK [Gathering Facts] ***************************************************************************************** ok: [192.168.10.121] ok: [192.168.10.120] TASK [go_install : copy go_tgz to client] ********************************************************************** changed: [192.168.10.120] changed: [192.168.10.121] TASK [go_install : copy install_go_script to client] *********************************************************** changed: [192.168.10.120] changed: [192.168.10.121] TASK [go_install : install go] ********************************************************************************* skipping: [192.168.10.120] skipping: [192.168.10.121] PLAY RECAP ***************************************************************************************************** 192.168.10.120 : ok=3 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 192.168.10.121 : ok=3 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 root@myxps:/etc/ansible# ansible-playbook go.yml [WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths PLAY [all] ****************************************************************************************************************************************************************** TASK [Gathering Facts] ****************************************************************************************************************************************************** ok: [192.168.10.121] ok: [192.168.10.120] TASK [go_install : copy go_tgz to client] *********************************************************************************************************************************** changed: [192.168.10.120] changed: [192.168.10.121] TASK [go_install : copy install_go_script to client] ************************************************************************************************************************ changed: [192.168.10.120] changed: [192.168.10.121] TASK [go_install : install go] ********************************************************************************************************************************************** changed: [192.168.10.120] changed: [192.168.10.121] PLAY RECAP ****************************************************************************************************************************************************************** 192.168.10.120 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.10.121 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
分发文件
cat /etc/ansible/hosts [intra] 192.168.10.120 192.168.10.121 ansible intra -m copy -a "src=/home/evan/data/devops/node-v14.17.6-linux-x64.tar.xz dest=/root/"