Ansible-playbook 简单实例(学习笔记十八)

  1. 云栖社区>
  2. 博客>
  3. 正文

Ansible-playbook 简单实例(学习笔记十八)

sktj 2018-03-27 11:19:00 浏览945
展开阅读全文

1、test.yml,执行任务:安装wget,更换仓储源,获取信息等

  • hosts: all

    gather_facts: false

    tasks:

    • name: yum wget

      yum: pkg=wget state=latest

    • name: mv old repo

      shell: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

    • name: download repo

      shell: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

    • name: get status

      shell: netstat -tnlup

2、执行结果:


img_3cce96c05cc54bf6459709774e1d4539.png
image.png

3、yaml使用变量的语法为{{变量}}:

  • hosts: all

    gather_facts: false

    remote_user: test

    vars:
    user1: test1
    user2: test2

    tasks:

    • name: create user

      user: name={{user1}}

4、执行结果:


img_f0f9df07e0b8516d601ac53de0a2e599.png
image.png

网友评论

登录后评论
0/500
评论
sktj
+ 关注