flectrag
第一题
[root@control ~]# yum -y install ansible
[root@control ~]# su - greg
Last login: Sun Nov 13 15:47:44 CST 2022 on pts/1
[greg@control ~]$ mkdir ansible
[greg@control ~]$ cd ansible/
[greg@control ansible]$ ls
[greg@control ansible]$ cp /etc/ansible/ansible.cfg .
[greg@control ansible]$ ls
ansible.cfg
[greg@control ansible]$ vim inventory
[dev]
node1
[test]
node2
[prod]
node3
node4
[blancers]
node5
[webservers:children]
prod
[greg@control ansible]$ vim ansible.cfg
[defaults]
inventory = /home/greg/ansible/inventory
remote_user = greg
roles_path = /home/greg/ansible/roles
host_key_checking = false
[privilege_escalation]
become = true
become_method = sudo
become_user = root
become_ask_pass = false
[greg@control ansible]$ mkdir roles
[greg@control ansible]$ ls
ansible.cfg inventory roles
[greg@control ansible]$ ansible all -m ping
第二题
[greg@control ansible]$ cat adhoc.sh
#!/bin/bash
ansible all -m yum_repository -a "name=EX294_BASE description='EX294 base software' file=rhel_dvd baseurl=http://content/rhel8.0/x86_64/dvd/BaseOS gpgcheck=yes gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release enabled=yes"
ansible all -m yum_repository -a "name=EX294_STREAM description='EX294 stream software' file=rhel_dvd baseurl=http://content/rhel8.0/x86_64/dvd/AppStream gpgcheck=yes gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release enabled=yes"
[greg@control ansible]$ chmod +x adhoc.sh
[greg@control ansible]$ ./adhoc.sh
第三题
[greg@control ansible]$ vim packages.yml
---
- name: install
hosts: dev,test,prod
tasks:
- name: install mariadb php
yum:
name:
- php
- mariadb
state: present
- name: install group pkgs
hosts: dev
tasks:
- name: install Development Tools
yum:
name: "@RPM Development Tools"
state: present
- name: update all pkgs
yum:
name: '*'
state: latest
[greg@control ansible]$ ansible-playbook packages.yml
第四题
[greg@control ansible]$ cp -r /usr/share/ansible/roles/rhel-system-roles.timesync/ /home/greg/ansible/roles/timesync
[greg@control ansible]$ ls
adhoc.sh ansible.cfg inventory packages.yml roles
[greg@control ansible]$ vim timesync.yml
[greg@control ansible]$ cat timesync.yml
---
- name: set time sync
hosts: all
vars:
timesync_ntp_servers:
- hostname: 172.25.254.254
iburst: yes
roles:
- timesync
使用selinux角色
配置该角色,开启所有受控节点的selinux
[greg@control ansible]$ cp -r /usr/share/ansible/roles/rhel-system