LiuYuan's Blog
This is LiuYuan's Blog
Toggle navigation
LiuYuan's Blog
Home
Docker相关
MySQL相关
Ansible相关
维护脚本相关
Windows系统脚本
Python相关
Nginx相关
About Me
Archives
Tags
ansible安装
2024-06-19 15:27:28
97
0
0
admin
#生成密钥,默认回车即可 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 #公共角色文件 执行命令 ansible all -m ping ansible test -m shell -a "date" 拷贝文件 ansible -i /etc/ansible/hosts test -m copy -a "src=/tmp/zabbix_agent-5.0.17-linux-4.12-ppc64le-static.tar.gz dest=/home/adm_chaowu.zhang/ owner=root group=root mode=0777" ansible -i test -m unarchive -a 'src=/etc/bin/zabbix_agent.tar.gz dest=/usr/local copy=no mode=0755' ansible -i /etc/ansible/hosts test -m shell "tar -zxvf /etc/bin/zabbix_agent.tar.gz -C /usr/local" ansible all -a 'chdir=/docker/ppmt-web-admin/data/ tar zxvf dist.tar.gz' playbook示例 --- - hosts: server gather_facts: false tasks: - name: Run update_server.sh script with parameter become: true shell: /data/luckyxp/update_server.sh "{{ tag }}" args: executable: /bin/bash register: shell_result - debug: var: shell_result.stdout_lines 运行ansible playbook ansible-playbook /data/luckyxp_v2/update_server.yaml --extra-vars "tag=4" #传参 ansible-playbook /data/luckyxp_v2/update_server.yaml
Pre:
MySQL备份脚本
Next:
nginx配置
0
likes
97
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Footer
Table of content