ansible ----- command , shell , raw, script模块

command , shell , raw, script 模块

1)ping模块

[root@ansible .ssh]# ansible web1 -m ping

2)command模块

[root@ansible .ssh]# ansible web1 -m command -a 'chdir=/tmp touch f1'  //创建成功

3)shell模块

[root@ansible .ssh]# ansible web1 -m shell -a 'chdir=/tmp touch f2'  //创建成功
[root@web1 ~]# cd /tmp/
[root@web1 tmp]# ls    //在web1上面查看
f2

4)raw模块

[root@ansible .ssh]# ansible web1 -m raw -a 'chdir=/tmp touch f3'  
//文件可以创建,但无法切换目录,文件在用户家目录下生成
web1 | SUCCESS | rc=0 >>
Shared connection to web1 closed.

[root@web1 tmp]# cd /root/
[root@web1 ~]# ls        //在web1上面查看 
f3

5)script模块

对于太复杂的命令,可以写个脚本,然后用script模块执行

在web1主机上创建zhangsan3用户,修改zhangsan3的密码为123456,设置zhangsan3第一次登陆必须修改密码

用命令写:

[root@ansible .ssh]# ansible web1 -m shell -a 'useradd zhangsan3'
[root@ansible .ssh]# ansible web1 -m shell -a 'echo 123456 | passwd --stdin zhangsan3'
[root@ansible .ssh]# ssh -l zhangsan3 web1
zhangsan3@web1's password:   //输入zhangsan3的密码


[root@ansible .ssh]# ansible web1 -m shell -a 'chage -d 0     zhangsan3'   
[root@ansible .ssh]# ssh -l zhangsan3 web1

用脚本写,script模块执行:

[root@ansible .ssh]# vim user.sh 
#!/bin/bash
useradd zhangsan3 
echo 123456 | passwd --stdin zhangsan3 
chage -d 0 zhangsan3
echo

[root@ansible .ssh]# ansible web1 -m script -a './user.sh'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值