标签:etc agentless rtu user name client node ansi 活跃
AnsiblePython
开发[root@centos7-node3 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@centos7-node3 ~]# yum -y install python36 python36-devel git nss curl curl-devel
[root@centos7-node3 ~]# pip3 install virtualenv
[root@centos7-node3 ~]# useradd deploy
[root@centos7-node3 ~]# su - deploy
[deploy@centos7-node3 ~]$ virtualenv -p /usr/bin/python3.6 .py3-a2.5-env
[deploy@centos7-node3 ~]$ source .py3-a2.5-env/bin/activate #激活环境
(.py3-a2.5-env) [deploy@centos7-node3 ~]$ pip install paramiko PyYAML jinja2
[deploy@centos7-node3 ~]$ git clone https://github.com/ansible/ansible.git
(.py3-a2.5-env) [deploy@centos7-node3 ~]$ mv ansible .py3-a2.5-env/
(.py3-a2.5-env) [deploy@centos7-node3 ~]$ cd .py3-a2.5-env/ansible/
(.py3-a2.5-env) [deploy@centos7-node3 ansible]$ git checkout stable-2.5
(.py3-a2.5-env) [deploy@centos7-node3 ansible]$ source /home/deploy/.py3-a2.5-env/ansible/hacking/env-setup -q #加载环境
(.py3-a2.5-env) [deploy@centos7-node3 ansible]$ ansible --version #安装完成
(.py3-a2.5-env) [deploy@centos7-node3 ~]$ ssh-keygen -t rsa
(.py3-a2.5-env) [deploy@centos7-node3 ~]$ ssh-copy-id -i /home/deploy/.ssh/id_rsa.pub root@192.168.56.15
(.py3-a2.5-env) [deploy@centos7-node3 ~]$ mkdir test_playbooks
(.py3-a2.5-env) [deploy@centos7-node3 ~]$ cd test_playbooks/
(.py3-a2.5-env) [deploy@centos7-node3 test_playbooks]$ mkdir inventory
(.py3-a2.5-env) [deploy@centos7-node3 test_playbooks]$ mkdir roles
(.py3-a2.5-env) [deploy@centos7-node3 test_playbooks]$ vim inventory/testenv
[testservers]
centos7-node5
[testservers:vars]
servername=centos7-node5
user=root
output=/root/test.txt
(.py3-a2.5-env) [deploy@centos7-node3 test_playbooks]$ mkdir roles/testbox/tasks -p
(.py3-a2.5-env) [deploy@centos7-node3 test_playbooks]$ vim roles/testbox/tasks/main.yaml
(.py3-a2.5-env) [deploy@centos7-node3 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) [deploy@centos7-node3 test_playbooks]$ vim deploy.yml
- hosts: "testservers"
gather_facts: true
remote_user: root
roles:
- testbox
[root@centos7-node3 ~]# 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) [deploy@centos7-node3 test_playbooks]$ ansible-playbook deploy.yml
标签:etc agentless rtu user name client node ansi 活跃
原文地址:https://blog.51cto.com/13812615/2488650