ansible角色

本文档详细介绍了如何使用Ansible在RHEL系统中应用timesync、selinux角色,以及从Ansible Galaxy安装和创建自定义角色。包括安装NTP服务、配置SELinux、下载并安装haproxy和phpinfo角色,以及创建和使用apache角色来部署HTTP服务。此外,还展示了如何使用balancer角色实现负载均衡和phpinfo角色展示PHP信息。
摘要由CSDN通过智能技术生成

linux ansible角色

在RH294环境中完成以下题目
1、使用RHEL系统角色
安装 RHEL 系统角色软件包,并创建符合以下条件的playbook /home/student/ansible/timesync.yml:
在所有受管节点上运行
使用 timesync 角色
配置该角色,以使用当前有效的 NTP 提供商
配置该角色,以使用时间服务器 classroom.example.com
配置该角色,以启用 iburst 参数

[student@workstation ansible]$ ls
ansible.cfg  inventory  roles
[student@workstation ansible]$ sudo yum -y install rhel-system-roles
[student@workstation ansible]$ cp -r /usr/share/ansible/roles/rhel-system-roles.timesync/  /home/student/ansible/roles/timesync
[student@workstation ansible]$ vim timesync.yml
---
- name: set time sync
  hosts: all
  vars:  
    timesync_ntp_servers:
      - hostname: classroom.example.com
        iburst: yes
  roles:
    - timesync
[student@workstation ansible]$ ansible-playbook timesync.yml

2、使用selinux角色
配置该角色,编写selinux.yml的playbook开启所有受控节点的selinux

[student@workstation ansible]$ cp -r /usr/share/ansible/roles/rhel-system-roles.selinux  /home/student/ansible/roles/selinux
[student@workstation ansible]$ ansible-galaxy list
# /home/student/ansible/roles
- timesync, (unknown version)
- selinux, (unknown version)
[student@workstation ansible]$ vim selinux.yml
---
- name: set selinux
  hosts: all
  vars: 
    selinux_state: enforcing
  roles: 
    - role: selinux
      become: true
[student@workstation ansible]$ ansible-playbook selinux.yml

3、使用Ansible Galaxy安装角色
使用 Ansible Galaxy 和要求文件 /home/student/ansible/roles/requirements.yml,从以下 URL 下载角色并安装到 /home/student/ansible/roles:
http://content.example.com/haproxy.tar.gz 此角色的名称应当为 balancer
http://content.example.com/phpinfo.tar.gz 此角色的名称应当为 phpinfo

[student@workstation ansible]$ vim roles/requirements.yml
---
- name: balancer
  src: http://content.example.com/ansible2.8/haproxy.tar.gz
- name: phpinfo
  src: http://content.example.com/ansible2.8/phpinfo.tar.gz
[student@workstation ansible]$ ansible-galaxy install -r requirements.yml -p roles/

4、创建和使用角色
根据下列要求,在/home/student/ansible/roles中创建名为apache的角色:
httpd软件包已安装,设为在系统启动时启用并启动
防火墙已启用并正在运行,并使用允许访问Web服务器的规则
模板文件 index.html.j2 已存在,用于创建具有以下输出的文件/var/www/html/index.html:
Welcome to HOSTNAME on IPADDRESS
其中,HOSTNAME是受管节点的完全限定域名,IPADDRESS则是受管节点的IP地址。
按照下方所述,创建一个使用此角色的playbook /home/student/ansible/newrole.yml:
该playbook在webservers主机组中的主机上运行

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值