ansible使用普通用户免密登陆+sudo提权


前提:从ansible控制端使用test用户可以免密登陆所有被控制端,并且被控端test用户支持sudo提权

# ansible主机清单
cat /etc/ansible/hosts

[online-a1]
172.17.149.162 ansible_ssh_user=test

[online-a2]
172.17.149.140 ansible_ssh_user=test

[online-a3]
172.17.149.120 ansible_ssh_user=test

[online-a4]
172.17.149.145 ansible_ssh_user=test

[online-as]
172.17.149.162 ansible_ssh_user=test
172.17.149.140 ansible_ssh_user=test
172.17.149.120 ansible_ssh_user=test
172.17.149.145 ansible_ssh_user=test

# ansible配置文件
/etc/ansible/ansible.cfg

取消注释的行:
remote_tmp     = ~/.ansible/tmp
inventory      = /etc/ansible/hosts
host_key_checking = False

# yaml文件内容
cat test.yaml
- hosts: online-as
  become: true
  tasks:
    - name: just test
      shell: mkdir -p /root/test/test2

# 命令行ansible-doc测试
ansible online-as -m shell -a 'ls -lh /root/' -become=true


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM