1. hosts文件
[test-hosts]
192.168.32.128
192.168.32.129
192.168.32.130
[all:vars]
ansible_ssh_user=test
ansible_sudo_pass='123456'
2. ping 模块
ansible -i conf/hosts test-hosts -b --become-user=root -m ping
3. shell 模块
ansible -i conf/hosts test-hosts -b --become-user=root -m shell -a 'sh /tmp/1.sh'
4. copy 模块
ansible -i conf/hosts test-hosts -b --become-user=root -m copy -a 'src=package/1.txt dest=/tmp owner=test group=test mode=0755'
5. playbook 编辑
- name: copy file
hosts: test-hosts
gather_facts: no
vars:
remote_user: test
become: yes
become_user: root
become_method: sudo
become_pass: 123456
tasks:
-name: copy script file
copy:
src: "/tmp/1.sh"
dest: "/tmp"
owner: root
group: root
mode: 0644
-name: run shell script
shell: |
sh /tmp/1.sh > /tmp/1.log
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。