逆时针 2020-04-20
Python
开发[ ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [ ~]# yum -y install python36 python36-devel git nss curl curl-devel [ ~]# pip3 install virtualenv [ ~]# useradd deploy [ ~]# su - deploy [ ~]$ virtualenv -p /usr/bin/python3.6 .py3-a2.5-env [ ~]$ source .py3-a2.5-env/bin/activate #激活环境 (.py3-a2.5-env) [ ~]$ pip install paramiko PyYAML jinja2 [ ~]$ git clone https://github.com/ansible/ansible.git (.py3-a2.5-env) [ ~]$ mv ansible .py3-a2.5-env/ (.py3-a2.5-env) [ ~]$ cd .py3-a2.5-env/ansible/ (.py3-a2.5-env) [ ansible]$ git checkout stable-2.5 (.py3-a2.5-env) [ ansible]$ source /home/deploy/.py3-a2.5-env/ansible/hacking/env-setup -q #加载环境 (.py3-a2.5-env) [ ansible]$ ansible --version #安装完成
(.py3-a2.5-env) [ ~]$ ssh-keygen -t rsa (.py3-a2.5-env) [ ~]$ ssh-copy-id -i /home/deploy/.ssh/id_rsa.pub
(.py3-a2.5-env) [ ~]$ mkdir test_playbooks (.py3-a2.5-env) [ ~]$ cd test_playbooks/ (.py3-a2.5-env) [ test_playbooks]$ mkdir inventory (.py3-a2.5-env) [ test_playbooks]$ mkdir roles (.py3-a2.5-env) [ test_playbooks]$ vim inventory/testenv [testservers] centos7-node5 [testservers:vars] servername=centos7-node5 user=root output=/root/test.txt (.py3-a2.5-env) [ test_playbooks]$ mkdir roles/testbox/tasks -p (.py3-a2.5-env) [ test_playbooks]$ vim roles/testbox/tasks/main.yaml (.py3-a2.5-env) [ test_playbooks]$ vim roles/testbox/tasks/main.yaml - name: Print server name and user to remote testbox shell: "echo ‘Currently {{ user }} is logging {{ servername }}‘ >> {{output}}" (.py3-a2.5-env) [ test_playbooks]$ vim deploy.yml - hosts: "testservers" gather_facts: true remote_user: root roles: - testbox
[ ~]# vim /etc/hosts 192.168.56.11 centos7-node1 192.168.56.12 centos7-node2 192.168.56.13 centos7-node3 192.168.56.14 centos7-node4 192.168.56.15 centos7-node5
(.py3-a2.5-env) [ test_playbooks]$ ansible-playbook deploy.yml