admin管理员组文章数量:1566353
https://blog.csdn/qq_35702095/article/details/90486379?utm_medium=distribute.pc_relevant.none-task-blog-title-2&spm=1001.2101.3001.4242
ansible 普通用户执行root权限操作
熟悉开机关机重启 2019-05-23 19:53:05 8757 收藏 6
分类专栏: ansible 文章标签: ansible root
版权
ansible -h可以看到有
--become (-b)
--become-method
--become-user
--ask-become-pass (-K)大写K
四个参数,利用这四个参数可以在ansible命令和playbook中用普通用户执行root操作。
命令: ansible 10.12.3.27,10.31.2.38 -m shell -a 'date' -b --become-method su --become-user root --ask-become-pass(-K)大写K
输入密码后,相当于用root执行了date命令,可以把date换成 cat /etc/shadow验证root权限。 多个ip(主机列表)的主机需要相同的root密码(只用输入一次),密码不同可以分多次或者直接配好密码。
如果想配好密码,可以在/etc/ansible/hosts为每个机器添加密码或者为组添加密码。例如:
[groupa]
10.10.10.1 ansible_become_pass=rootpwd1
10.10.10.2 ansible_become_pass=rootpwd2
[groupb]
10.10.10.3
10.10.10.4
[groupb:vars]
ansible_become_pass=rootpwd34
如果失败可能是ssh过去后,执行su -后没有提示输入密码,应该是编码问题,在受控机器上执行echo export en_CN.utf-8 >>~/.bashrc,然后再执行ansible命令试试。
playbook:
---
- hosts: 10.12.3.28,10.12.3.27
become: yes
become_user: root
become_method: su
tasks:
- name: date
shell: date
版权声明:本文标题:ansible 普通用户执行root权限操作 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1727082992a1097069.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论