;,
"md5sum": "85239384c0243e32ef2e37e8cd3b3114",
"mode": "0644",
"owner": "root",
"size": 32,
"src": "/root/.ansible/tmp/ansible-tmp-1666515163.7038138-132258-153764762517348/source",
"state": "file",
"uid": 0
}
//在受控主机上查看到a.sh
[root@ansible ~]# ansible 192.168.118.130 -a 'ls /scripts/'192.168.118.130 | CHANGED | rc=0 >>
a.sh
test.sh
ansible常用模块之group
group模块用于在受控机上添加或删除组
//创建一个runtime组gid为255
[root@ansible ~]# ansible 192.168.118.130 -m group -a 'name=runtime gid=255 state=present'
192.168.118.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"gid": 255,
"name": "runtime",
"state": "present",
"system": false
}
//可以在受控主机上查看到已经有了gid为250的runtime组
[root@ansible ~]# ansible 192.168.118.130 -a 'grep runtime /etc/group'192.168.118.130 | CHANGED | rc=0 >>
runtime:x:255:
//删除受控机上的runtime组
[root@ansible ~]# ansible 192.168.118.130 -m group -a 'name=runtime state=absent'
192.168.118.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"name": "runtime",
"state": "absent"
}
[root@ansible ~]# ansible 192.168.118.130 -a 'grep runtime /etc/group'
192.168.118.130 | FAILED | rc=1 >>
non-zero return code
ansible常用模块之user
user模块用于管理受控机的用户帐号。
//在受控机上添加一个系统用户,用户名为mysql,uid为306,设置其shell为/sbin/nologin,无家目录
[root@ansible ~]# ansible 192.168.118.130 -m user -a 'name=mysql uid=306 system=yes create_home=no shell=/sbin/nologin state=present'
192.168.118.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"comment": "",
"create_home": false,
"group": 306,
"home": "/home/mysql",
"name": "mysql",
"shell": "/sbin/nologin",
"state": "present",
"system": true,
"uid": 306
}
[root@ansible ~]# ansible 192.168.118.130 -a 'grep mysql /etc/passwd'
192.168.118.130 | CHANGED | rc=0 >>
mysql:x:306:306::/home/mysql:/sbin/nologin
//修改mysql用户的uid为366
[root@ansible ~]# ansible 192.168.118.130 -m user -a 'name=mysql uid=366'
192.168.118.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"append": false,
"changed": true,
"comment": "",
"group": 306,
"home": "/home/mysql",
"move_home": false,
"name": "mysql",
"shell": "/sbin/nologin",
"state": "present",
"uid": 366
}
[root@ansible ~]# ansible 192.168.118.130 -a 'grep mysql /etc/passwd'192.168.118.130 | CHANGED | rc=0 >>
mysql:x:366:306::/home/m