• puppet的使用:puppet的hello world


    这个例子完成将master节点上的一个文件放至agent节点上的功能

    创建要传输的文件

    echo “helloWorld” > /etc/puppet/modules/puppet-example/files/hello
    

    不使用module

    创建site.pp

    直接把对agent的操作写入site.pp文件中。

    touch /etc/puppet/manifests/site.pp
    

    内容如下:

     node 'agentHostname' {
        file { '/root/tmp/hello':
            owner => 'root',
            group => 'root',
            mode => '0440',
            source => 'puppet:///modules/puppet-example/hello'
            }
        }
    

    启动agent

    在agent上执行如下命令:
    puppet agent --test
    就会看到/root/tmp/hello文件了。

    使用module

    创建module

    module的目录结构是固定的,目录的结构一般如下所示:
    ├── files
    ├── manifests
    └── templates

    • files: 属于模块的文件

    • manifests: 脚本文件

    • templates:模板文件

      md -p /etc/puppet/modules/puppet-example/{files,templates,manifests}

    生成init.pp文件

    init.pp是模块必须要有的文件,放至在模块的manifests路径下。

    touch /etc/puppet/modules/puppet-example/manifests/init.pp
    
    class puppet-example {
        file { '/root/tmp/hello':
            owner => 'root',
            group => 'root',
            mode => '0440',
            source => 'puppet:///modules/puppet-example/hello'
        }
    }
    

    生成site.pp文件

    touch /etc/puppet/manifests/site.pp
    

    内容如下:
    node 'agentHostname' {
    include puppet-example
    }
    至此,文件全部创建完毕。

    目录结构

    最终的目录结构如下所示:
    /etc/puppet# tree

    ├── manifests
    │   └── site.pp
    ├── modules
    │   └── puppet-example
    │       ├── files
    │       │   └── hello
    │       ├── manifests
    │       │   └── init.pp
    │       └── templates
    └── templates
    

    启动agent

    在agent上执行如下命令:
    puppet agent --test
    就会看到/root/tmp/hello文件了。

  • 相关阅读:
    Linux文件权限学习总结
    【转】Hibernate和ibatis的比较
    Spring AOP原理及拦截器
    Spring AOP (下)
    Spring AOP (上)
    SQL语句限定查询知识点总结
    多线程知识点总结
    关于tomcat那些事情
    java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException 的解决办法
    cacti 与 nagios 一些总结 【八】
  • 原文地址:https://www.cnblogs.com/cuimiemie/p/6442663.html
Copyright © 2020-2023  润新知