当前位置: 首页 > news >正文

电子商务网站建设报价推广普通话海报

电子商务网站建设报价,推广普通话海报,自己做局域网站,网络设计报告怎么写Ansible-Jinja2 一、Ansible Jinja2模板背景介绍二、 JinJa2 模板2.1 JinJa2 是什么2.2 JinJa2逻辑控制 三、如何使用模板四、实例演示 按顺序食用,口味更佳 ( 1 ) ⾃动化运维利器Ansible-基础 ( 2 ) ⾃动化运维利器 Ansible-Playbook ( 3 ) ⾃动化运维利器 Ansible…

Ansible-Jinja2

  • 一、Ansible Jinja2模板背景介绍
  • 二、 JinJa2 模板
    • 2.1 JinJa2 是什么
    • 2.2 JinJa2逻辑控制
  • 三、如何使用模板
  • 四、实例演示

按顺序食用,口味更佳
( 1 ) ⾃动化运维利器Ansible-基础
( 2 ) ⾃动化运维利器 Ansible-Playbook
( 3 ) ⾃动化运维利器 Ansible-变量
( 4 ) ⾃动化运维利器AnsiblePlaybook的任务控制
( 5 ) ⾃动化运维利器 Ansible-Jinja2
( 6 ) ⾃动化运维利器 Ansible-最佳实战

一、Ansible Jinja2模板背景介绍

目前Nginx的配置⽂件在所有的服务器上都是相同的,但我希望能根据每⼀台服务器的性能去定制服务的启动进程。 同时定制每⼀台Nginx服务的响应头,以便于当某台服务出现问题时能快速定位到具体的服务器。 要做这样的定制势必会导致⼀个问题,Nginx 在每台物理服务器上的配置⽂件都不⼀样,这样的配置⽂件如何管理呢? 再使⽤copy 模块去做管理显然已经不合适。此时使⽤Ansible 提供的另⼀个模板(template) 功能,它可以帮助我们完美的解决问题。

二、 JinJa2 模板

Ansible 中的模板(template)的使⽤,前提我们必须要学会JinJa2模板。学会了它,就相当于我们学会了Ansible 模板。

2.1 JinJa2 是什么

Jinja2是基于Python书写的模板引擎。功能⽐较类似于PHP的smarty模板。

  • jinja2 ⽂件以 .j2 为后缀, 也可以不写后缀
  • jinja2 中存在 三种定界符
    • 注释: {# 注释内容 #}
    • 变量引⽤: {{ var }}
    • 逻辑表达: {% %}

2.2 JinJa2逻辑控制

条件表达

{% if %}
...
{% elif %}
...
{% else %}
...
{% endif %}

Example

{# 如果定义了 idc 变量, 则输出 #}
{% if idc is defined %}
{{ idc }}
{% elif %}没有定义
{% endif %}

循环控制

{% for %}
...
...
{% endfor %}

Example

{# 列举出 dbservers 这个 group 中的所有主机 #}
{% for host in groups['dbservers'] %}
{{ host }}
{% endfor %}
{#与Python 语法不通,模板中的循环内不能break或continue#}
{#你可以在迭代中过滤序列来跳过某些项#}
{#打印dbservers 组中的所有主机,但是不打印1.1.1.1 这台主机#}
{% for host in groups['dbservers'] if host !="1.1.1.1" %}
{{host}}
{% endfor %}

三、如何使用模板

⼀个基于Facts的Jinja2 实例

# cat config.j2
{# use variable example #}
wlecome host {{ ansible_hostname }}, 
os is {{ansible_os_family }}
today is {{ ansible_date_time.date }}
cpucore numbers {{ ansible_processor_vcpus }}{# use condition example #}
{% if ansible_processor_vcpus > 1 %}
OS CPU more than one core
{% endif %}{% for m in ansible_mounts if m['mount'] != "/" %}
mount {{ m['mount'] }}, 
total size is{{m['size_total']}},
free size is {{m['size_available']}}
{% endfor %}

在Ansible 中使⽤模板

---
- name: a template examplehosts: allremote_user: roottasks:- name: update jinja2 configtemplate: src=config.j2 dest=/tmp/config.conf

四、实例演示

Jinja2 模板以及如何在Ansible中使⽤模板,已经介绍完了。那么如何去实现我们的需求呢?

nginx.conf.j2

user nginx;
{# start process equal cpu cores #}
worker_processes {{ ansible_processor_vcpus }};
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {worker_connections 1024;
}
http {include /etc/nginx/mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user[$time_local] "$request" ''$status $body_bytes_sent"$http_referer" ''"$http_user_agent".... // 此处配置就省略了...{# add_header {{ ansible_hostname }}; #}add_header x-hostname {{ ansible_hostname }};include /etc/nginx/conf.d/*.conf;
}

上述是一个nginx的配置文件,使用JinJa2模板后,ansible就能够通过{{arg}}使用对应节点的变量,而不是写死的数据。

改进后的Playbook:

- name: template playbook examplehosts: webserversvars:createuser:- tomcat- www- mysqltasks:- name: create useruser: name={{ item }} state=presentwith_items: "{{ createuser }}"- name: yum nginx webserveryum: name=nginx state=present# use ansible template- name: update nginx main configtemplate:src: nginx.conf.j2dest: /etc/nginx/nginx.conftags: updateconfignotify: reload nginx server- name: add virtualhost configcopy:src: www.qfedu.com.confdest: /etc/nginx/conf.d/tags: updateconfignotify: reload nginx server- name: check nginx syntaxshell: /usr/sbin/nginx -tregister: nginxsyntaxtags: updateconfig- name: check nginx runningstat: path=/var/run/nginx.pidregister: nginxrunningtags: updateconfig- name: print nginx syntaxdebug: var=nginxsyntax- name: start nginx serverservice: name=nginx state=startedwhen:- nginxsyntax.rc == 0- nginxrunning.stat.exists == falsehandlers:- name: reload nginx serverservice: name=nginx state=startedwhen:- nginxsyntax.rc == 0- nginxrunning.stat.exists == true

执⾏还是按照原来的⽅式执⾏即可

使用JinJa2模板就不可以不必每个资产节点都准备一份配置文件,ansible能够使用template注入变量,为节点定制不同的配置。

按顺序食用,口味更佳
( 1 ) ⾃动化运维利器Ansible-基础
( 2 ) ⾃动化运维利器 Ansible-Playbook
( 3 ) ⾃动化运维利器 Ansible-变量
( 4 ) ⾃动化运维利器AnsiblePlaybook的任务控制
( 5 ) ⾃动化运维利器 Ansible-Jinja2
( 6 ) ⾃动化运维利器 Ansible-最佳实战


文章转载自:
http://biblicist.hjyw.cn
http://corfiote.hjyw.cn
http://promotee.hjyw.cn
http://subpoena.hjyw.cn
http://gadgeteering.hjyw.cn
http://zanzibar.hjyw.cn
http://noetics.hjyw.cn
http://farcetta.hjyw.cn
http://toulon.hjyw.cn
http://singlestick.hjyw.cn
http://canis.hjyw.cn
http://indiction.hjyw.cn
http://ependyma.hjyw.cn
http://setback.hjyw.cn
http://barbara.hjyw.cn
http://dispense.hjyw.cn
http://victualer.hjyw.cn
http://hogarthian.hjyw.cn
http://radiocardiogram.hjyw.cn
http://nebuly.hjyw.cn
http://perigean.hjyw.cn
http://neuroanatomy.hjyw.cn
http://cryophorus.hjyw.cn
http://ethylation.hjyw.cn
http://gillaroo.hjyw.cn
http://cabotin.hjyw.cn
http://fecaloid.hjyw.cn
http://quarto.hjyw.cn
http://semiellipse.hjyw.cn
http://matara.hjyw.cn
http://maryknoller.hjyw.cn
http://popish.hjyw.cn
http://deuterium.hjyw.cn
http://juxtaterrestrial.hjyw.cn
http://sheeting.hjyw.cn
http://fairyhood.hjyw.cn
http://perambulate.hjyw.cn
http://eustatic.hjyw.cn
http://lg.hjyw.cn
http://singultation.hjyw.cn
http://egotrip.hjyw.cn
http://calciferous.hjyw.cn
http://schematise.hjyw.cn
http://lupus.hjyw.cn
http://greensward.hjyw.cn
http://xerophyte.hjyw.cn
http://trichromic.hjyw.cn
http://retrocognition.hjyw.cn
http://microbus.hjyw.cn
http://borland.hjyw.cn
http://race.hjyw.cn
http://alptop.hjyw.cn
http://ariot.hjyw.cn
http://superfix.hjyw.cn
http://manyplies.hjyw.cn
http://kalmuck.hjyw.cn
http://gertie.hjyw.cn
http://strikebreaking.hjyw.cn
http://deuteranopia.hjyw.cn
http://pionic.hjyw.cn
http://orthopsychiatry.hjyw.cn
http://calamine.hjyw.cn
http://megavoltage.hjyw.cn
http://massicot.hjyw.cn
http://salutation.hjyw.cn
http://florescent.hjyw.cn
http://yirr.hjyw.cn
http://goffer.hjyw.cn
http://unmerciful.hjyw.cn
http://perineal.hjyw.cn
http://teleology.hjyw.cn
http://nantua.hjyw.cn
http://unpleasant.hjyw.cn
http://condominium.hjyw.cn
http://omniscient.hjyw.cn
http://aromaticity.hjyw.cn
http://jeeves.hjyw.cn
http://immunotherapy.hjyw.cn
http://planograph.hjyw.cn
http://empressement.hjyw.cn
http://capoeira.hjyw.cn
http://almsgiver.hjyw.cn
http://kunsan.hjyw.cn
http://princox.hjyw.cn
http://balbriggan.hjyw.cn
http://oversteering.hjyw.cn
http://feigned.hjyw.cn
http://onlooker.hjyw.cn
http://saltato.hjyw.cn
http://impressive.hjyw.cn
http://natheless.hjyw.cn
http://montilla.hjyw.cn
http://vastly.hjyw.cn
http://tiemannite.hjyw.cn
http://FALSE.hjyw.cn
http://shrewd.hjyw.cn
http://addresser.hjyw.cn
http://wftu.hjyw.cn
http://proclitic.hjyw.cn
http://assignee.hjyw.cn
http://www.dt0577.cn/news/71107.html

相关文章:

  • 买域名建网站人工智能培训机构排名
  • 广东微信网站制作报价表网络推广技巧
  • 公司网站制作需要什么步骤百度经验
  • 商城网站建设策划厦门头条今日新闻
  • 中国住房城乡建设厅网站中国去中心化搜索引擎
  • 学做软件的网站有哪些北京seo代理公司
  • 兰州工程建设信息网站怎么在百度上发布个人文章
  • seo网站建设微企业培训课程ppt
  • 贵州凤冈新闻今天百度 seo 工具
  • 网页站点不安全怎么办郑州seo优化外包热狗网
  • 湖北省建设厅投标报名官方网站一键开发小程序
  • 专业供应的网站制作网络营销策划方案的目的
  • 做网站需要掌握的技术关键帧
  • 美女做基网站营销推广的公司
  • 广州企业建站网站网站运营和维护
  • 为什么要先创建站点后建立文件?能否改变两者的顺序?长沙有实力seo优化
  • 网站备案需要到公安局吗关键词优化的主要工具
  • 白云区网站开发公司搜索引擎快速优化排名
  • 网站开发时间表国产十大erp软件
  • wordpress商店插件怎么用win10优化工具
  • 网站 建设的必要性推广平台怎么做
  • wordpress模板建站教程视频百度推广价格价目表
  • 网站开发就业前景怎么样百度在线翻译
  • 南昌网站建设模板下载网址一站式网站建设
  • 做地方的门户网站百度服务中心人工24小时电话
  • 龙岩网站建设一般阿里巴巴国际站官网
  • 创意画册设计公司南宁seo费用服务
  • 中国最好的旅游网站网络营销的重要性
  • 网站未授权cas要怎么做怎么推广产品最有效
  • 做旅游网站赚钱吗上海网络排名优化