#生成密钥,默认回车即可
ssh-keygen
#拷贝密钥至主机
ssh-copy-id root@192.168.47.135
ssh-copy-id root@192.168.47.136
cd /root/.SSH
cat id_rsa.pub > authorized_keys
vi /etc/ansible/hosts
[test]
192.168.47.134
192.168.47.135
192.168.47.136
yum -y install epel-release.noarch
yum -y install tree
yum -y install ansible
windows
# 安装pywinrm模块
pip install pywinrm
#在控制节点上创建或编辑Ansible的主机清单文件(例如 /etc/ansible/hosts):
[windows]
windows_host ansible_host=<windows_ip>
[windows:vars]
ansible_user=<your_username>
ansible_password=<your_password>
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_winrm_server_cert_validation=ignore
#创建一个简单的Ansible剧本(例如 win_ping.yml),测试连接到Windows主机:
---
- name: Test connection to Windows host
hosts: windows
tasks:
- name: Ping the Windows host
win_ping:
#在控制节点上运行Ansible剧本:
ansible-playbook win_ping.yml
通过tree查看ansible有哪些文件,当然还有很多文件没有列举出来
tree /etc/ansible/
/etc/ansible/
├── ansible.cfg #配置文件
├── hosts #主机清单文件
└── roles