Ansible连接windows机器&docker容器
来源:互联网 发布:基础英语词汇知乎 编辑:程序博客网 时间:2024/06/18 11:06
拖拖拖,,,这个ansible多种连接方式6月就写了部分总结,终于来搞完它了。。。
ansible有多种连接方式,一般大多使用OpenSSH,类似的还有Paramiko SSH(基于python)、smart、local,这几种比较简单。重点讲一下WinRM和Docker连接,主要是因为官网对于windows连接讲的不清楚,国内的资料也不多。
WinRM连接
1、系统/软件信息
Windows OS: windows7 64bit
Linux OS:CentOS 7.3
Ansible version: 2.3
Powershell version:3.0
官网要求powershell升级到3.0,注意一下。
2、windows设置
1)以管理员身份运行PowerShell,执行下列命令设置允许执行脚本。
PS C:\Windows\system32> set-executionpolicy remotesigned执行策略更改执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 http://go.microsoft.com/fwlink/?LinkID=135170中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?[Y] 是(Y) [N] 否(N) [S] 挂起(S) [?] 帮助 (默认值为“Y”): y
2)下载ConfigureRemotingForAnsible.ps1脚本。
Ansible官网提供链接:https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1
3)使用ansible官网提供的四个命令执行ps脚本,每个命令的注释写在#后面:
#Pass the -CertValidityDays option to customize the expiration date of the generated certificate:PS C:\Windows\system32> powershell.exe -File 'E:\ansible\ConfigureRemotingForAnsible.ps1' -CertValidityDays 100
#Pass the -EnableCredSSP switch to enable CredSSP as an authentication option:PS C:\Windows\system32> powershell.exe -File 'E:\ansible\ConfigureRemotingForAnsible.ps1' -EnableCredSSPcfg : http://schemas.microsoft.com/wbem/wsman/1/config/service/authlang : zh-CNBasic : trueKerberos : trueNegotiate : trueCertificate : falseCredSSP : trueCbtHardeningLevel : Relaxed
#Pass the -ForceNewSSLCert switch to force a new SSL certificate to be attached to an already existing winrm listener. (Avoids SSL winrm errors on syspreped Windows images after the CN changes):PS C:\Windows\system32> powershell.exe -File 'E:\ansible\ConfigureRemotingForAnsible.ps1' -ForceNewSSLCertSelf-signed SSL certificate generated; thumbprint: A6CFC074C16F424B1C5E0EC70F153CD4E097A0B1wxf : http://schemas.xmlsoap.org/ws/2004/09/transfera : http://schemas.xmlsoap.org/ws/2004/08/addressingw : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsdlang : zh-CNAddress : http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymousReferenceParameters : ReferenceParameters
PS C:\Windows\system32> powershell.exe -File 'E:\ansible\ConfigureRemotingForAnsible.ps1' -SkipNetworkProfileCheck
4)使用管理员权限运行cmd,配置winrm服务的加密方式为允许非加密。
C:\Windows\system32>winrm set winrm/config/service @{AllowUnencrypted="true"}Service RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD) MaxConcurrentOperations = 4294967295 MaxConcurrentOperationsPerUser = 1500 EnumerationTimeoutms = 240000 MaxConnections = 300 MaxPacketRetrievalTimeSeconds = 120 AllowUnencrypted = true Auth Basic = true Kerberos = true Negotiate = true Certificate = false CredSSP = true CbtHardeningLevel = Relaxed DefaultPorts HTTP = 5985 HTTPS = 5986 IPv4Filter = * IPv6Filter = * EnableCompatibilityHttpListener = false EnableCompatibilityHttpsListener = false CertificateThumbprint AllowRemoteAccess = true
3、Linux设置
1)安装pywinrm
# yum install -y python-pip# pip install "pywinrm>=0.2.2"
Tips:不能联网的话,可以在有网络的机器把pkg下载好,再pip装到不能联网的机器上。
2)在hosts中配置windows信息,使用win_ping模块连接。
[root@ansible ~]# cat /etc/ansible/hosts[windows]wannengPC ansible_host=windows_server_ip[windows:vars]ansible_user=Administratoransible_password=windows_Administrator_passwordansible_connection=winrmansible_port=5985
这边注意一下,最好使用Administrator用户,若设为administrator组的其他用户,可能会认证失败(嗯,亲测失败了)。
[root@ansible ~]# ansible -m win_ping windowswannengPC | SUCCESS => { "changed": false, "ping": "pong"}
以上,是我使用ansible连接windows的步骤,其中遇到不少错误,参考链接也放在下面。
http://docs.ansible.com/ansible/latest/intro_windows.html
http://www.torutk.com/projects/swe/wiki/Ansible%E3%82%92Windows%E4%B8%8A%E3%81%AEWSL%E3%81%AB%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB
https://github.com/ansible/ansible/issues/16478
https://github.com/diyan/pywinrm/issues/114
Docker连接
docker连接比较简单,跟着官网来就OK。
1、先装好docker,然后启动服务。
[root@ansible ~]# systemctl start docker[root@ansible ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE10.11.12.13:44381/centos 7 67591570dd29 7 months ago 191.8 MB[root@ansible ~]# docker run -it 67591570dd29 /bin/bash[root@ed725094b6d7 /]#
[root@ansible ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESed725094b6d7 67591570dd29 "/bin/bash" 50 seconds ago Up 48 seconds grave_mccarthy
2、设置ansible hosts
[root@ansible ~]# cat /etc/ansible/hosts[docker]docker1[docker:vars]ansible_host=grave_mccarthyansible_user=rootansible_connection=docker
注意这边的ansible_host要与docker容器的Name一致。
[root@ansible ~]# ansible -m ping dockerdocker1 | SUCCESS => { "changed": false, "ping": "pong"}
以上是docker的连接,基本没难点。
最近在搞saltstack,估计也会总结一下我遇到的errors,从连接方式就感觉saltstack和ansible的不同。saltstack比ansible功能要多很多,当然也复杂一点,具体之后再写总结。
- Ansible连接windows机器&docker容器
- ansible 连接 windows (通过powershell)
- [Docker]5.Docker 容器连接
- docker容器连接
- docker容器连接
- Docker 容器连接
- Docker 容器连接
- docker连接两个容器
- 利用Ansible部署运行Apache(http)的Docker容器
- Docker容器的连接与docker-compose
- Docker入门实战-SSH连接docker容器
- docker容器的网络连接
- 使用ssh连接docker容器
- 初识docker—容器连接
- 在Windows宿主机中ssh连接虚拟机CentOS中的Docker容器
- |ansible |chef |docker比较
- windows机器连接mac
- Docker 使用方法总结之:容器的连接
- hive left semi join讲解
- ubuntu16.04 gcc/g++降级
- reids 基本数据类型命令
- 利用Java实现表达式二叉树
- SQL索引
- Ansible连接windows机器&docker容器
- fullcalendar案例一<原>
- 【map && spfa求正权回路】HDU
- JS程序设计基础:变量,算术、关系、赋值、复合赋值、逻辑、位运算符与表达式
- git 的常用命令
- Linux下的sort排序命令详解(一)
- ShowcaseView,一个快速简单的用户指引库.
- 数据库的设计理论
- C/C++内存泄漏及检测