ansible使用用户密码远程执行命令
ansible使用用户密码远程执行命令是使用sshpass,免去ssh输入密码的交互。
- 安装ansible
yum install ansible
- 修改ansible配置
vim /etc/ansible/ansible.cfg
# defaults section增加如下配置:
[defaults]
host_key_checking = False # 第一次远程ssh主机需要将机器指纹添加到known_hosts,此设置忽略该步骤
command_warnings=False #忽略ansible执行命令的告警信息
deprecation_warnings=False
- 增加远程机器
vim /etc/ansible/hosts
# 密码包含特殊符号,需要使用双引号
10.83.192.20 ansible_host=10.83.192.20 ansible_user=admin ansible_password="xxx"
10.83.192.21 ansible_host=10.83.192.21 ansible_user=admin ansible_password="xxx"
- 执行命令
# 不加setsid或nohup,会报"RECEIVED SIGNAL 1: SIGHUP",导致服务启动失败
ansible 10.83.192.20 -m shell -a 'setsid hdfs --daemon start datanode'
ansible 10.83.192.20 -m shell -a 'setsid hdfs --daemon stop datanode'
ansible 10.83.192.21 -m shell -a 'nohup hdfs --daemon start datanode &'
SIGHUP
If a process is being run from terminal and that terminal suddenly goes away then the process receives this signal. “HUP” is short for “hang up” and refers to hanging up the telephone in the days of telephone modems.
nohup、setsid、Daemon介绍
https://www.cnblogs.com/csuliujia/p/9939502.html