第十七次作业

本文档展示了如何使用Ansible Playbook创建和管理Yum仓库,包括CentOS的base和appstream仓库,以及配置Web服务器,安装httpd和php,创建并测试index.php页面。此外,还涵盖了在远程节点上添加用户xiaohong,设置免密登录和sudo权限。
摘要由CSDN通过智能技术生成

1.受管主机部署yum仓库

要求:

仓库1 :
Name: base
​ Description: baseos
​ Base url: https://mirrors.163.com/centos-vault/8.5.2111/BaseOS/x86_64/os/
​ 需要验证软件包 GPG 签名
​ GPG key 在 /etc/pki/rpm-gpg/RPM-GPG-KEY-*
​ 启用此软件仓库

仓库 2:
Name: app
Description: appstream
Base url: https://mirrors.163.com/centos-vault/8.5.2111/AppStream/x86_64/os/
需要验证软件包 GPG 签名
GPG key 在: /etc/pki/rpm-gpg/RPM-GPG-KEY-*
启用此软件仓库

代码:
[root@localhost ~]# vim 1-create-yum.yml
- name: play1
  hosts: all
  tasks:
    - name: create base
      yum_repository:
        name: base
        description: baseos
        baseurl: https://mirrors.aliyun.com/centos-vault/8.2.2004/BaseOS/x86_64/os/
        gpgcheck: yes
    - name: create appstream
      yum_repository:
        name: app
        description: appstream
        baseurl: https://mirrors.aliyun.com/centos-vault/8.2.2004/AppStream/x86_64/os/
        gpgcheck: yes
    - name: install vsftpd
      yum:
        name: vsftpd
        state: latest

2.给web主机组写一个playbook,该playbook有两个play,第一个play可以保证在web主机组上安装httpd和php,确保web主机组的/var/www/html/目录下面有一个文件为index.php,内容如下:

$ cat /var/www/html/index.php
phpinfo();
该playbook里面的第二个play用于测试该web主机组的web服务能否被成功访问index.php内容。
代码:

设置web组

[web]
master
node01

[root@localhost ~]# vim 1-create-yum.yml

---
- name: play1
  hosts: web
  tasks:
    - name: install httpd
      yum:
        name:
          - httpd
          - php
        state: latest
    - name: create index
      copy:
        content: "<?php\nphpinfo();\n"
        dest: /var/www/html/index.php
    - name: delete index.html
      file:
        path: /var/www/html/index.html
        state: absent
    - name: add a firewalld rule
      firewalld:
        service: http
        permanent: true
        state: enabled
        immediate: true
    - name: restart httpd
      service:
        name: httpd
        state: restarted

- name: play2
  hosts: master
  tasks:
    - name: ceshi master
      uri:
        url: http://master

3.在受控节点上添加一个普通用户xiaohong,配置当前控制节点的用户可以免密登录xiaohong用户,并且xiaohong可以sudo。

[root@localhost ~]# vim 3-useradd.yml

---
- name: play1
  hosts: node01
  tasks:
    - name: useradd xiaohong
      user:
        name: xiaohong
        state: present

    - name: xiaohong sudoers
      lineinfile:
        line: "xiaohong ALL=(ALL) NOPASSWD:ALL"
        path: /etc/sudoers
    - authorized_key:
        state: present
        user: xiaohong
        key: "{{ lookup('file', '/home/admin/.ssh/id_rsa.pub') }}"

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

E.W.S.A.P.

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

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

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

打赏作者

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

抵扣说明:

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

余额充值