#ping检测目标主机是否可达
ansible all -f 3 -m ping
#在远程服务器上执行命令
ansible pcvm -m command -a "systemctl status sshd"
#分发创建的脚本文件到远程
ansible pcvm -m copy -a "src=/root/mycnf.sh dest=/data/ mode=0755 owner=root"
#远程执行
ansible pvcm -m shell -a "/data/mycnf.sh"
#测试执行
ansible pvcm -m shell -C "/data/mycnf.sh"
# chronyd 允许开机启动
ansible all -m systemd -a 'name=chronyd enabled=yes'
# chronyd 启动/重启
ansible all -m systemd -a 'name=chronyd state=started'
ansible all -m systemd -a 'name=chronyd state=restarted'
# 安装SNMP
ansible all -m yum -a 'name=net-snmp,net-snmp-utils state=installed'
# 查看端口
ansible all -a 'netstat -tnlpu'
# 批量安装软件
ansible all -m yum -a 'name=vim,lrzsz,wget,bzip2,chrony,gcc,gcc-c++,kernel-devel,openssh-clients,tree,pam-devel,zlib-devel,openssl-devel,man,unzip,parted,parted-devel,net-tools,autofs,bash-completion,epel-release state=installed'
版权归属:
ZERO
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区