目 录CONTENT

文章目录

Ansible命令使用

ZERO
2023-03-04 / 0 评论 / 0 点赞 / 85 阅读 / 0 字
#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'

0

评论区