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

网站建设 海豚弯wordpress新特性

网站建设 海豚弯,wordpress新特性,指数基金定投技巧,选择好的佛山网站建设描述# 幂等性是在实际应用中经常需要考虑的概念#xff0c;尤其是运维中。相较于将幂等性理解为各种异常情况的综合处理#xff0c;将其理解为执行时需要考虑到在前次执行产生的影响的情况下能够正常执行则会更加容易接近业务需求。   ansible包含众多的模块#xff0c;大…描述# 幂等性是在实际应用中经常需要考虑的概念尤其是运维中。相较于将幂等性理解为各种异常情况的综合处理将其理解为执行时需要考虑到在前次执行产生的影响的情况下能够正常执行则会更加容易接近业务需求。   ansible包含众多的模块大部分内置模块都能够保证操作的幂等性即相关操作的多次执行能够达到相同结果这一特性不会出现多次执行带来副作用的影响。但是也有不满足幂等原则的比如shell模块、raw模块、command模块。 幂等操作和非幂等操作的对比 场景说明 比如实现删除一个临时性的文件/root/testfile的操作如果希望其在相同的条件下多次执行能够保持相同的结果和不会带来其它副作用至少需要保证此操作在/root/testfile文件存在和不存在的情况下都能正常动作。 # 当采用raw模块执行shell命令删除文件第一次删除是成功当执行第二次删除也是成功的但是在生产环境这结果是不理想的比如重启一个服务你会随便重启服务吗 [rootServer-1~]# touch /root/testfile [rootServer-1~]# ansible localhost -m shell -a rm -rf testfile localhost | CHANGED | rc0 [rootServer-1~]# ansible localhost -m shell -a rm -rf testfile localhost | CHANGED | rc0 # 当采用file 模块执行删除文件第一次执行删除文件成功changed: true多次执行删除文件都是同一样的结果不会带来副作用的影响changed: Fasle。 [rootServer-1~]# touch /root/testfile [rootServer-1~]# ansible localhost -m file -a path/root/testfile stateabsent localhost | CHANGED {changed: true, path: /root/testfile, state: absent } [rootServer-1~]# ansible localhost -m file -a path/root/testfile stateabsent localhost | SUCCESS {changed: false, path: /root/testfile, state: absent }那file模块是如何实现幂等的呢如下是file模块执行absent文件时的代码(有中文注释) vim /usr/lib/python2.7/site-packages/ansible/modules/files/file.py ..... def get_state(path): Find out current state b_path to_bytes(path, errorssurrogate_or_strict)try:if os.path.lexists(b_path): # 如果文件存在返回file文件不存在返回absentif os.path.islink(b_path):return linkelif os.path.isdir(b_path):return directoryelif os.stat(b_path).st_nlink 1:return hard# could be many other things, but defaulting to filereturn file return absentexcept OSError as e:if e.errno errno.ENOENT: # It may already have been removedreturn absentelse:raisedef ensure_absent(path):b_path to_bytes(path, errorssurrogate_or_strict)prev_state get_state(b_path) # 获取文件的状态result {}if prev_state ! absent: # 当prev_statedirectory or file 为真diff initial_diff(path, absent, prev_state)if not module.check_mode:if prev_state directory: # 如果prev_statedirectory, 则删除目录try:shutil.rmtree(b_path, ignore_errorsFalse)except Exception as e:raise AnsibleModuleError(results{msg: rmtree failed: %s % to_native(e)})else:try:os.unlink(b_path) # 如果prev_statefile, 则删除文件except OSError as e:if e.errno ! errno.ENOENT: # It may already have been removedraise AnsibleModuleError(results{msg: unlinking failed: %s % to_native(e),path: path})result.update({path: path, changed: True, diff: diff, state: absent}) # 删除文件成功动作有改变changedTrueelse:result.update({path: path, changed: False, state: absent}) # 如果prev_stateabsent, 动作没有改变changedFalse, 实现多次操作执行不会有任何改变。return resultdef main():global modulemodule AnsibleModule(argument_specdict(statedict(typestr, choices[absent, directory, file, hard, link, touch]),pathdict(typepath, requiredTrue, aliases[dest, name]),_original_basenamedict(typestr), # Internal use only, for recursive opsrecursedict(typebool, defaultFalse),forcedict(typebool, defaultFalse), # Note: Should not be in file_common_args in futurefollowdict(typebool, defaultTrue), # Note: Different default than file_common_args_diff_peekdict(typebool), # Internal use only, for internal checks in the action pluginssrcdict(typepath), # Note: Should not be in file_common_args in futuremodification_timedict(typestr),modification_time_formatdict(typestr, default%Y%m%d%H%M.%S),access_timedict(typestr),access_time_formatdict(typestr, default%Y%m%d%H%M.%S),),add_file_common_argsTrue,supports_check_modeTrue,)# When we rewrite basic.py, we will do something similar to this on instantiating an AnsibleModulesys.excepthook _ansible_excepthookadditional_parameter_handling(module.params)params module.paramsstate params[state]recurse params[recurse]force params[force]follow params[follow]path params[path]src params[src]timestamps {}timestamps[modification_time] keep_backward_compatibility_on_timestamps(params[modification_time], state)timestamps[modification_time_format] params[modification_time_format]timestamps[access_time] keep_backward_compatibility_on_timestamps(params[access_time], state)timestamps[access_time_format] params[access_time_format]# short-circuit for diff_peekif params[_diff_peek] is not None:appears_binary execute_diff_peek(to_bytes(path, errorssurrogate_or_strict))module.exit_json(pathpath, changedFalse, appears_binaryappears_binary)if state file:result ensure_file_attributes(path, follow, timestamps)elif state directory:result ensure_directory(path, follow, recurse, timestamps)elif state link:result ensure_symlink(path, src, follow, force, timestamps)elif state hard:result ensure_hardlink(path, src, follow, force, timestamps)elif state touch:result execute_touch(path, follow, timestamps)elif state absent: result ensure_absent(path) # 执行删除文件时调用方法 def ensure_absentmodule.exit_json(**result)if __name__ __main__:main()
http://www.zqtcl.cn/news/542411/

相关文章:

  • 江苏省 建设 注册中心网站首页淮南建筑网
  • 网站备案核wordpress页面菜单
  • 凤阳县城乡建设局网站设计本app下载
  • 网站建设实用教程网站后台制作表格
  • 微信官方网站注册新开的网页游戏平台
  • 福州专业建站网站代码的重点内容是什么
  • jsp网站架构网站设计的主要内容
  • html电子商务网站模板wordpress 随机阅读数
  • 湖南省军区强军网网站群建设项目免费网页托管
  • 网站背景图政协网站 两学一做专题研讨
  • 买域名建网站郑州做网站优化运营商
  • 建设宠物店网站114查询
  • 怎么查网站关键词排名微信与与网站建设
  • 湖州高端网站建设医疗网站源码
  • 有什么网站是做兼职的直播视频怎么录制
  • 扬州市网站建设工作室免费模板网站建设
  • 网站大全全部优秀网站设计流程
  • 授权网站系统网站标题如何修改
  • 商城网站大概多少钱考证培训机构报名网站
  • 马鞍山做网站怎么看网站谁做的
  • 网站建设捌金手指专业7网站如何设置广告
  • 做网站用什么浏览器好工程公司工作总结
  • 温州做网站哪家好为wordpress移动端
  • 温州平阳县企业网站搭建推荐建立网站的技术路径
  • php c2c网站开发的 书营销型网站sempk
  • 网站建设专业网站设计公司物格网陕西建省级执法人才库
  • 网站后台管理密码忘了建设网站简单吗
  • 做网站在哪里网站开发平台有哪些
  • 网站域名的建立推荐一个两学一做的网站
  • 网站开发开源框架企业影视广告制作公司