ansible 使用

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=https://www.it610.com/article/package/1.txt dest=/tmp owner=test group=test mode=0755'

【ansible 使用】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

    推荐阅读