ansible教程

pip3 install ansible

配置一个名为hosts的文件中包含你要操作的主机

text

[spark]
cdhmaster
cdhslave1
cdhslave2
cdhslave3
cdhslave4
cdhslave5
cdhslave6
cdhslave7
cdhslave8

创建任务文件 testcat.yml

yml

- hosts: spark
  user: nisl
  tasks:
      - name: cat securelog
        become: yes
        become_user: root
        become_method: sudo
        shell: cat /var/log/secure

运行任务

bash

ansible-playbook -i hosts --ask-become-pass  testcat.yml