1121作业

1、以all主机组为目标执行id命令

[xiaoming@centos7 chap01]$ ansible all -m command  -a  'id'
node01 | CHANGED | rc=0 >>
uid=0(root) gid=0(root) 组=0(root) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
centos7 | CHANGED | rc=0 >>
uid=0(root) gid=0(root) 组=0(root) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
node02 | CHANGED | rc=0 >>
uid=0(root) gid=0(root) groups=0(root),1001(mygroup) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

2、使用copy模块修改所有主机上的/etc/motd文件内容为welcome to ansible

[xiaoming@centos7 chap01]$ ansible all -m copy  -a 'content="welcom to ansible\n" dest=/etc/motd'
centos7 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "checksum": "ac533aed11b0decf60acd68ec36359c11992d8d3",
    "dest": "/etc/motd",
    "gid": 0,
    "group": "root",
    "md5sum": "feb7f11b486bc2178fcadc3c72f26d79",
    "mode": "0644",
    "owner": "root",
    "secontext": "system_u:object_r:etc_t:s0",
    "size": 18,
    "src": "/home/xiaoming/.ansible/tmp/ansible-tmp-1669134053.79-8034-140887631386806/source",
    "state": "file",
    "uid": 0
}
node01 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "checksum": "ac533aed11b0decf60acd68ec36359c11992d8d3",
    "dest": "/etc/motd",
    "gid": 0,
    "group": "root",
    "md5sum": "feb7f11b486bc2178fcadc3c72f26d79",
    "mode": "0644",
    "owner": "root",
    "secontext": "system_u:object_r:etc_t:s0",
    "size": 18,
    "src": "/home/xiaoming/.ansible/tmp/ansible-tmp-1669134053.79-8033-163661273656350/source",
    "state": "file",
    "uid": 0
}
node02 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "checksum": "ac533aed11b0decf60acd68ec36359c11992d8d3",
    "dest": "/etc/motd",
    "gid": 0,
    "group": "root",
    "md5sum": "feb7f11b486bc2178fcadc3c72f26d79",
    "mode": "0644",
    "owner": "root",
    "secontext": "system_u:object_r:etc_t:s0",
    "size": 18,
    "src": "/home/xiaoming/.ansible/tmp/ansible-tmp-1669134053.82-8032-189534451343401/source",
    "state": "file",
    "uid": 0
}

3、使用command模块查看/etc/motd文件的内容

[xiaoming@centos7 chap01]$ ansible all -m command  -a  'cat /etc/motd'
node01 | CHANGED | rc=0 >>
welcom to ansible
centos7 | CHANGED | rc=0 >>
welcom to ansible
node02 | CHANGED | rc=0 >>
welcom to ansible

4、使用user模块创建用户wukong,uid为2000

[xiaoming@centos7 chap01]$ ansible all -m user  -a  'name=wukong state=present uid=2000'
centos7 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "append": false,
    "changed": true,
    "comment": "",
    "group": 1001,
    "home": "/home/wukong",
    "move_home": false,
    "name": "wukong",
    "shell": "/bin/bash",
    "state": "present",
    "uid": 2000
}
node01 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "append": false,
    "changed": true,
    "comment": "",
    "group": 1003,
    "home": "/home/wukong",
    "move_home": false,
    "name": "wukong",
    "shell": "/bin/bash",
    "state": "present",
    "uid": 2000
}
node02 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "append": false,
    "changed": true,
    "comment": "",
    "group": 3462,
    "home": "/home/wukong",
    "move_home": false,
    "name": "wukong",
    "shell": "/bin/bash",
    "state": "present",
    "uid": 2000
}

5、使用yum模块安装httpd软件包并使用service模块启动该服务

#yum模块安装httpd
[xiaoming@centos7 chap01]$ ansible all -m yum -a 'name=httpd'
node01 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "msg": "Nothing to do",
    "rc": 0,
    "results": []
}
node02 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "msg": "Nothing to do",
    "rc": 0,
    "results": []
}
centos7 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "msg": "",
    "rc": 0,
    "results": [
        "httpd-2.4.6-95.el7.centos.x86_64 providing httpd is already installed"
    ]
}

#service模块启动该服务
[xiaoming@centos7 chap01]$ ansible all -m service -a 'name=httpd state=started'
centos7 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "name": "httpd",
    "state": "started",
    "status": {
node01 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "name": "httpd",
    "state": "started",
    "status": {

node02 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "name": "httpd",
    "state": "started",
    "status": {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

RongChuJie

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值