关于ansible:ansible-使用

56次阅读

共计 660 个字符,预计需要花费 2 分钟才能阅读完成。

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

正文完
 0