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

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、执行结果:


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、执行结果:


image.png

你可能感兴趣的:(Ansible-playbook 简单实例(学习笔记十八))