vim ansible.cfg
[defaults]
inventory=/etc/ansible/hosts //主机列表配置文件
remote_user=redhat //要在受管主机上登录的用户名称,没有指定则是当前用户
ask_pass=True //每次执行ansible命令是否询问ssh密码
[root@server ~]# vim /etc/sudoers
root ALL=(ALL) ALL
redhat ALL=(ALL) NOPASSWD: ALL //授权redhat用户在所有计算机上以所有用户身份免密执行所有命令
[root@node1 ~]# vim /etc/sudoers
root ALL=(ALL) ALL
redhat ALL=(ALL) NOPASSWD: ALL
[root@student ~]# vim ansible.cfg
[defaults]
inventory=/etc/ansible/hosts
remote_user=redhat
ask_pass=False
sudo_user=root //默认的sudo用户
ask_sudo_pass=False //提权时是否密码验证
[root@xixi ~]# vim ansible.cfg
[defaults]
inventory=/etc/ansible/hosts
remote_user=redhat
ask_pass=False
sudo_user=root
ask_sudo_pass=False //特权升级
[privilege_escalation]
become=True //连接后是否在受管主机上切换用户,默认会切换到root下
become_method=sudo //如何切换用户
become_user=root //受管主机切换到的哪个用户
become_ask_pass=False //是否为become_method提示输入密码
1.在控制主机生成密钥
ssh-keygen -t rsa
2.发送公钥到受控主机
ssh-copy-id -i node1