ansible的搭建配置,ansible搭建配置


Ansible简介
    ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包括:
(1)、连接插件connection plugins:负责和被监控端实现通信;
(2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机;
(3)、各种模块核心模块、command模块、自定义模块;
(4)、借助于插件完成记录日志邮件等功能;
(5)、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务。
Windows下Ansible工作模式
Ansible 从1.7+版本开始支持Windows,但前提是管理机必须为Linux系统,远程主机的通信方式也由SSH变更为PowerShell,同时管理机必须预安装Python的Winrm模块,方可和远程Windows主机正常通信,但PowerShell需3.0+版本且Management Framework 3.0+版本,实测Windows 7 SP1和Windows Server 2008 R2及以上版本系统经简单配置可正常与Ansible通信。简单总结如下:
(1)    管理机必须为Linux系统且需预安装Python Winrm模块
(2)    底层通信基于PowerShell,版本为3.0+,Management Framework版本为3.0+
(3)    远程主机开启Winrm服务
Ansible管理机部署安装
1). 对管理主机的要求
    目前,只要机器上安装了 Python 2.6 或 Python 2.7 (windows系统不可以做控制主机),都可以运行Ansible.
主机的系统可以是 Red Hat, Debian, CentOS, OS X, BSD的各种版本,等等.
这个节点就是安装ansible的节点。
Shell(NMC)># yum -y install epel-release
Shell(NMC)># yum -y install ansible.noarch


配置管理主机:vim /etc/ansible/hosts
免密登陆设置:
   49  ssh-keygen -t rsa -P
  
   52  find / -name ssh-keygen
   53  cd /usr/bin/
   57  ansible sdyy02 -m ping


   59  ansible 192.168.7.7 -m ping
   60  ssh-keygen -t rsa
   61  cd $HOME/.ssh
   63  ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.7.7
   64  ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.7.8
   65  vi /etc/ansible/ansible.cfg 
   66  ansible all -m ping
2)控制机安装Python winrm模块
tar zxvf pywinrm-0.2.2.tar.gz 
  211  tar -zxvf isodate-0.6.0.tar.gz 
  212  tar -zxvf xmlwitch-0.3.tar.gz 
  213  cd pywinrm-0.2.2/
  214  ls
  215  python setup.py install
  216  python
  217  ansible windows -m win_ping
Ansible使用命令
群组名称:sdyy
批量传输文件并备份: ansible sdyy -s -m copy -a 'src=/home/master/upload/list.jsp dest=目的路径 owner=webadmin group=webadmin backup=yes'
批量删除 :ansible sdyy -m shell -a "rm -rf /opt/cs.txt"
批量启动tomcat: ansible sdyy -m shell -a " nohup /opt/tomcat1.sh start owner=webadmin group=webadmin"   
批量关闭tomcat: ansible sdyy -m shell -a "/opt/tomcat1.sh stop owner=webadmin group=webadmin"


windows:
ping :ansible windows -m win_ping
拷贝:ansible windows -m win_copy -a 'src=/opt/cs.txt dest=D:\'
删除:ansible windows -m win_file -a "path=D:\cs.txt state=absent"


Windows配置:
和Linux发版版稍有区别,远程主机系统如为Windows需预先如下配置:
安装Framework 3.0+
更改powershell策略为remotesigned
升级PowerShell至3.0+
设置Windows远端管理,英文全称WS-Management(WinRM)
(1)安装Framework 3.0+
下载链接为:http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_x86_x64.exe。 下载至本地后双击左键安装即可,期间可能会多次重启,电脑需正常连接Internet。
(2)更改powershell策略为remotesigned
    set-executionpolicy remotesigned
(3)升级PowerShell至3.0+
Window 7和Windows Server 2008 R2默认安装的有PowerShell,但版本号一般为2.0版本,所以我们需升级至3.0+,如下图中数字1部分表示PowerShell版本过低需3.0+版本,数字2部分表示当前PowerShell版本为2.0。
 
(4)设置Windows远端管理(WS-Management,WinRM)
winrm service 默认都是未启用的状态,先查看状态;如无返回信息,则是没有启动;
winrm enumerate winrm/config/listener
针对winrm service 进行基础配置:
winrm quickconfig
查看winrm service listener:
winrm e winrm/config/listener
为winrm service 配置auth:
winrm set winrm/config/service/auth @{Basic="true"}
为winrm service 配置加密方式为允许非加密:
winrm set winrm/config/service @{AllowUnencrypted="true"}


ansible windows -m win_ping




错误说明
 
pip list
  229  ansible windows -m win_ping
  230  sudo pip uninstall request
  231  sudo pip uninstall requests
  232  pip install requests
  233  pip uninstall docopt
  234  sudo pip uninstall docopt
  235  sudo pip install docopt
  236  ansible windows -m win_ping
 
修改ansible的windows连接方式
vi /etc/ansible/hosts
[sdyy]
192.168.7.7
192.168.7.8
[windows]
192.168.7.11 ansible_ssh_user="Administrator" ansible_ssh_pass="SDyykj123" ansible_ssh_port=5985 ansible_connection=winrm











相关内容

    暂无相关文章