zoukankan      html  css  js  c++  java
  • playbook编写(四)

    文件处理

    文件处理的模块(常用)

    Blockinfile 该模块可以管理员在指定的文件中插入“一段文本”

    Copy 该模块主要用于拷贝文件,将控制节点上的文件拷贝到被管理主机

    Fatch 该模块从远程主机中拉取文件到被管理的节点

    Lineinfile 支持正则表达式

    File 修改文件权限

    State 查看文件状态

    Synchronize ------>等价于 rsync 批量同步文件

    Sefcontext 修改文件上下文永久生效,修改系统的 selinux 相关的配置文件

    使用 JINJA2 模版部署自定义文件

     · 修改文件时调用 JINJA2模版

    JINJA2介绍

     使用 JINJA2 模版

     

    [student@workstation file-template]$ cat motd.j2
          This is the system {{ ansible_facts['fqdn'] }}. 
          This is a {{ ansible_facts['distribution'] }} version {{ ansible_facts['distribution_version'] }} system. 
          Only use this system with permission. 
          Please report issues to: {{ system_owner }}.
    
    
    [student@workstation file-template]$ cat motd.yml  
          --- 
          - name: configure SOE   
            hosts: all   
            remote_user: devops   
            become: true   
            vars:     
              - system_owner: clyde@example.com   
            tasks:     
              - name: configure /etc/motd       
                template:         
                  src: motd.j2         
                  dest: /etc/motd         
                  owner: root         
                  group: root         
                  mode: 0644 

    练习:

    Generate a hosts file

    Download an initial template file from

    http://content.example.com/materials/hosts.j2 to /home/devops/ansible

    Complete the template so that it can be used to generate a file with a line for

    each inventory host in the same format as /etc/hosts

    Create a playbook called /home/devops/ansible/hosts.yml that uses this template

    to generate the file /etc/myhosts on hosts in the dev host group.

    When the playbook is run, the file /etc/myhosts on hosts in the dev host group should

    have a line for each managed host:

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

    172.25.250.10 servera.lab.example.com servera

    172.25.250.11 serverb.lab.example.com serverb

    172.25.250.12 serverc.lab.example.com serverc

    172.25.250.13 serverd.lab.example.com serverd

    172.25.250.14 servere.lab.example.com servere

    172.25.250.15 serverf.lab.example.com serverf

    NOTE: The order in which the inventory host names appear is not important. 

     

     登录被节点验证

     

  • 相关阅读:
    JMeter性能测试中控制业务比例
    软件版本命名规范
    软件测试方法——静态测试与动态测试
    安装BugFree 3.0.4时出现的问题
    Linux下给mysql创建用户分配权限
    LoadRunner 测试脚本
    linux dd命令详解
    Linux查看CPU和内存使用情况
    Error:java: 无效的源发行版: 10
    rf接口自动化之结果校验
  • 原文地址:https://www.cnblogs.com/leading-net/p/13286932.html
Copyright © 2011-2022 走看看