zoukankan      html  css  js  c++  java
  • 部署etcd中使用ansible进行变量初始化

    ansible-playbook 要进行默认变量的生产,可以依靠jinja 的模板渲染功能

    看几个官方给出的例子

    调用setup 中的变量   例如 setup 中的变量层级为 ansible_eth0_ipv4_address ---->['ansible_facts']['eth0']['ipv4']['address']


    {% for host in groups['app_servers'] %} {{ hostvars[host]['ansible_facts']['eth0']['ipv4']['address'] }} {% endfor %}

    调用 inventory中的变量
    {{ hostvars['test.example.com']['ansible_facts']['distribution'] }}
    {% if 'webserver' in group_names %}
       # some part of a configuration file that only applies to webservers
    {% endif %}

    调用运行时变量
    ansible_play_hosts is the full list of all hosts still active in the current play

    综合以上文档思考得出我们play book 如下

    TMP_NODES: "{% for h in ansible_play_hosts %}{{ hostvars[h]['name'] }}=http://{{ hostvars[h]['ansible_facts']['default_ipv4']['address'] }}:20002,{% endfor %}"
    ETCD_NODES: "{{ TMP_NODES.rstrip(',') }}"

    一定要在外层使用双引号

  • 相关阅读:
    Linux 间网线直连
    Ubuntu 14.04安装配置NFS
    Android Native IPC 方案支持情况
    使用WindowsAPI获取录音音频
    Ubuntu 64编译32位程序
    TensorFlow 安装 Ubuntu14.04
    纯css实现表单输入验证
    安装ELectron失败解决方案
    正则学习
    常见web攻击
  • 原文地址:https://www.cnblogs.com/leleyao/p/12374159.html
Copyright © 2011-2022 走看看