ansible verwandt

Befehlsmodul: Unterstützt grundlegende Shell-Befehle,unterstützt jedoch keine Pipeline-Operationen.

ansible -i /etc/ansible/hosts -m command -a ‘ls /root’

Alle Server laden das Redis-Installationspaket herunter,存放路径为/opt

ansible -i /etc/ansible/hosts all -m command -a ‘wget -c http://download.redis.io/releases/redis-5.0.7.tar.gz -P /opt’

查看下载的redis安装包
ansible -i /etc/ansible/hosts all -m command -a ‘ls /opt

raw和shell模块: Unterstützt grundlegende Shell-Befehle,也支持管道操作.

ansible -i /etc/ansible/hosts name|group -m raw/shell -a ‘ps -ef | grep httpd

file模块:

ansible -i /etc/ansible/hosts name|group -m file -a ‘path=/tmp/file state=touch

ansible -i /etc/ansible/hosts name|group -m file -a ‘path=/tmp/file state=absent

ansible -i /etc/ansible/hosts name|group -m file -a ‘path=/tmp/dic1 state=dictionary owner=root

gourp=root mode=755

ansible -i /etc/ansible/hosts name|group -m file -a ‘path=/tmp/dic1 state=absent

copy模块

ansible -i /etc/ansible/hosts name|group -m copy -a ‘src=/tmp/file dest=/opt/file owner=root

group=root mode=755 backup=yes|no

若发现报错

msg”: “Aborting, target uses selinux but python bindings (libselinux-python)

aren’t installed!”

则目标主机开启了selinux,需要安装ibselinux-python, 或者关闭selinux

执行 /usr/sbin/sestatus -v查看selinux状态

yum模块

ansible -i /etc/ansible/hosts name|group -m yum -a ‘name=httpd state=present’

ansible -i /etc/ansible/hosts name|group -m yum -a ‘name=httpd state=absent’

一次性安装多个rpm包,Z.B:
ansible -i /etc/ansible/hosts all -m yum -a ‘name=gcc,gcc-c++ state=present

service模块

service_module

ansible -i /etc/ansible/hosts cluster -m service -a ‘name=zabbix-agent state=restarted sleep=3

ansible非常强大. 以上是些只是些简单的操作, 更多命令参考 ansible-doc -l

Hinterlasse eine Antwort