Category - Ansible相关

2024-06-19 15:27:28    97    0    0
  1. #生成密钥,默认回车即可
  2. ssh-keygen
  3. #拷贝密钥至主机
  4. ssh-copy-id root@192.168.47.135
  5. ssh-copy-id root@192.168.47.136
  6. cd /root/.SSH
  7. cat id_rsa.pub > authorized_keys
  8. vi /etc/ansible/hosts
  9. [test]
  10. 192.168.47.134
  11. 192.168.47.135
  12. 192.168.47.136
  13. yum -y install epel-release.noarch
  14. yum -y install tree
  15. yum -y install ansible

windows

  1. # 安装pywinrm模块
  2. pip install pywinrm
  3. #在控制节点上创建或编辑Ansible的主机清单文件(例如 /etc/ansible/hosts):
  4. [windows]
  5. windows_host ansible_host=<windows_ip>
  6. [windows:vars]
  7. ansible_user=<your_username>
  8. ansible_password=<your_password>
  9. ansible_connection=winrm
  10. ansible_winrm_transport=basic
  11. ansible_winrm_server_cert_validation=ignore
  12. #创建一个简单的Ansible剧本(例如 win_ping.yml),测试连接到Windows主机:
  13. ---
  14. - name: Test connection to Windows host
  15. hosts: windows
  16. tasks:
  17. - name: Ping the Windows host
  18. win_ping:
  19. #在控制节点上运行Ansible剧本:
  20. ansible-playbook win_ping.yml

通过tree查看ansible有哪些文件,当然还有很多文件没有列举出来

  1. tree /etc/ansible/
  2. /etc/ansible/
  3. ├── ansible.cfg #配置文件
  4. ├── hosts #主机清单文件
  5. └── roles
Footer