make-Linux学习20201030

考试培训:

1、考题的地址和系统名称对应,最好带纸笔记录;
2、当前我们实验的密码是readhat
3、考试时候必须使用greg用户,放置到/home/greg/ansible/

(1)第一题
cp /etc/ansible/ansible.cfg /home/greg/ansible/ansible.cfg
host_key_checking = False
remote_user = root

(2)第二题创建和运行ansible临时命令
vim /home/greg/ansible/adhoc.sh
ansible all -m yum_repository -a 'name=“EX294_BASE” description=“EX294 base soft” basefile=“http://…” gpgkey=“xxxxx” enabled=yes ’

ansible all -m yum_repository -a 'name=“EX294_STEAM” description=“EX294 base soft” basefile=“http://…” gpgkey=“xxxxx” enabled=yes ’

bash adhoc.sh执行命令

(3)安装软件包
ansible-doc playbook(查阅如何配置)

vim /home/greg/ansible/packages.yml

  • name: 安装软件包A
    hosts: dev,test,prod
    tasks:

    • name: one
      yum:
      name: php
      state: latest
      -name: two
      yum:
      name: mariadb
      state: latest
  • name: 安装软件包B
    host: dev
    task:
    -name: one
    yum:
    name: “@RPM Developmet Tools”
    state: latest
    -name: two
    shell: “yum update * -y”

最后执行命令:
ansible-playbook packages.yml

(4)使用RHEL系统角色
vim /home/greg/ansible/timesync.yml

yum install
cd /usr/share/ansible/roles/
cp /usr/share/doc/rhel-system-roles/timesync/example-timesync.yml timesync.yml

ansible-galaxy list

vim timesync.yml

  • hosts: all
    times
    -hostname: 172.25.254.254

运行脚本
ansible-playbook timensync.yuml
此处红色报错不要关注,毕竟没有fase

(5)使用ansible Galaxy安装角色
vim /home/greg/ansible/roles/requirements.yuml
mkdir roles

  • src: http://materiasl/glaxy.tar
    name: balancer
  • src: http://mate/glas2.tar
    name: phpinfo
    如果考题没有要求。无须安装,
    ansible-galaxy -r requirement.yml
    ansible-galaxy -r /roles/requirement.yml

(6)创建和使用角色
角色:本地角色、galaxy角色、外部导入角色
ansible-galaxy init apache
ansible-galaxy -list
ls
cd apache/
cd task
查看文档ansible-doc yum
vim main.yml

  • name: one
    yum:
    name: httpd
    state: latest
  • name: two
    shell: “systemctl enable httpd” —取巧
    state:started
    enabled: yes
  • name:three
    shell: firewall-cmd --add-service=http —取巧
    firewalld:
    service: http
    permanet: yes用久生效
    immediate: yes当前生效
    state:enable
  • name: four
    temlate:
    src: index.html.j2
    dest: /var/html/index.html

cd /template
touch index.html

查看文档ansible-doc firewalld
查看文档ansible-doc template
ansible all -m setup -a ‘filter=“fqdn”’
ansible all -m setup -a ‘filter=“ip”’

ansible_fqdn

ansible_default_ipv4

cd /template/index.html.j2
Welcome to { {ansible_fqdn} } on { { ansible_default_ipv4.address } }

(7)从ansible galaxy使用角色
vim /home/greg/ansible/roles.yml

连续三天:ansible

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值