zoukankan      html  css  js  c++  java
  • 第一个简单yaml文件用ansile-playbook运行

    为何要学习yaml和json呢?这玩意在生产环境尤为重要。
    一、编写yaml文件
    ---
    - hosts: all
    tasks:
    - name: Install httpd
    yum: name=httpd state=present
    - name: test copy
    template: src=/root/1.txt dest=/root/1.txt
    notify:
    - Start chrony
    - name: ensure http is running
    service: name=httpd state=started
    handlers:
    - name: Start chrony
    service: name=chronyd state=started
    二、测试yaml语法
    [root@docker1 ~]# ansible-playbook http.yml --syntax-check
     
    playbook: http.yml
     
    三、编写主机文件hosts,类似inventory,其实名字无所谓,随意命名。
    [root@docker1 ~]# cat /root/hosts
    [httpd]
    192.168.3.141
    其实可以直接用ip,kolla-openstack用主机名或者域名都可以。
    三、执行ansible-playbook
    [root@docker1 ~]# ansible-playbook -i hosts http.yml -k
    SSH password:
    后面-k可以不加,采用免密登录,今晚时间有限,我就不搞免密了。
    看看执行结果:
     
    PLAY [all] ********************************************************************************************************************************************************
     
    TASK [Gathering Facts] ********************************************************************************************************************************************
    ok: [192.168.3.141]
     
    TASK [Install httpd] **********************************************************************************************************************************************
    ok: [192.168.3.141]
     
    TASK [test copy] **************************************************************************************************************************************************
    changed: [192.168.3.141]
     
    TASK [ensure http is running] *************************************************************************************************************************************
    changed: [192.168.3.141]
     
    RUNNING HANDLER [Start chrony] ************************************************************************************************************************************
    changed: [192.168.3.141]
     
    PLAY RECAP ********************************************************************************************************************************************************
    192.168.3.141 : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    其实内容标题都是我们自定义的。
    TASK [Gathering Facts] ------收集对象主机setup信息,这步可以前面加参数去掉。
  • 相关阅读:
    CodeForces 659F Polycarp and Hay
    CodeForces 713C Sonya and Problem Wihtout a Legend
    CodeForces 712D Memory and Scores
    CodeForces 689E Mike and Geometry Problem
    CodeForces 675D Tree Construction
    CodeForces 671A Recycling Bottles
    CodeForces 667C Reberland Linguistics
    CodeForces 672D Robin Hood
    CodeForces 675E Trains and Statistic
    CodeForces 676D Theseus and labyrinth
  • 原文地址:https://www.cnblogs.com/cloud-datacenter/p/13210883.html
Copyright © 2011-2022 走看看