关于ansible modules模块的使用

ansible做小范围的集群管理还是很棒的,我挺喜欢他的modules模块的,够直接 !!!  

我这里就说些常见的ansible的modules吧。

一看大家就懂了,就是服务状态的管理模块

ansible webservers -m service -a “name=httpd state=started”

ping模块
ansible webservers -m ping

基本命令
ansible webservers -m command -a “/sbin/reboot -t now”

关于redis的模块

[root@67 ~]# ansible web -m redis -a "command=flush flush_mode=all"
10.10.10.66 | success >> {
    "changed": true, 
    "flushed": true
}

[root@67 ~]# 

# Set local redis instance to be slave of melee.island on port 6377
– redis: command=slave master_host=melee.island master_port=6377

# Deactivate slave mode
– redis: command=slave slave_mode=master

# Flush all the redis db
– redis: command=flush flush_mode=all

# Flush only one db in a redis instance
– redis: command=flush db=1 flush_mode=db

# Configure local redis to have 10000 max clients
– redis: command=config name=maxclients value=10000

# Configure local redis to have lua time limit of 100 ms
– redis: command=config name=lua-time-limit value=100

还有mongodb的管理模块

# Create ‘burgers’ database user with name ‘bob’ and password ‘12345’.
– mongodb_user: database=burgers name=bob password=12345 state=present

# Delete ‘burgers’ database user with name ‘bob’.
– mongodb_user: database=burgers name=bob state=absent

# Define more users with various specific roles (if not defined, no roles is assigned, and the user will be added via pre mongo 2.2 style)
– mongodb_user: database=burgers name=ben password=12345 roles=’read’ state=present
– mongodb_user: database=burgers name=jim password=12345 roles=’readWrite,dbAdmin,userAdmin’ state=present
– mongodb_user: database=burgers name=joe password=12345 roles=’readWriteAnyDatabase’ state=present

# add a user to database in a replica set, the primary server is automatically discovered and written to
– mongodb_user: database=burgers name=bob replica_set=blecher password=12345 roles=’readWriteAnyDatabase’ state=present

在这里有大量的模块,大家可以好好看看,当然ansible也是可以自己开发模块的。   他的写法和saltstack有些相像。。。。


大家觉得文章对你有些作用! 如果想赏钱,可以用微信扫描下面的二维码,感谢!
另外再次标注博客原地址  xiaorui.cc

发表评论

邮箱地址不会被公开。 必填项已用*标注