设为首页 加入收藏

TOP

ansible常用模块的介绍与使用(四)
2023-07-23 13:38:52 】 浏览:157
Tags:ansible 常用模
;, "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
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Ansible部署LNMP 下一篇海思3516系列芯片SPI速率慢问题深..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目