ansible 高级自动化变量及变量过滤器

ansible 变量

  1. 变量可存放于多处位置
    1. roles
      • vars/main.yml
      • tasks/main.yml
      • handlers/main.yml
    2. playbook
      • 与 tasks 同列
      • 在每个task中单独定义

ansible变量过滤器

1. 变量类型

1. 不可迭代的基本数据
	1. 字符串
	2. 数字
	3. null值
2. 可迭代的复合数据
	1. 列表
	2. 字典
	3. 嵌套列表
	4. 一组字典的列表(items)

2. 通用变量过滤器

  1. mandatory
  2. default

3. 基础变量过滤器

  1. 数字
    1. + - * / // % * **
  2. 字符串
    1. replace
    2. regex_replace
    3. 首字母大写
    4. 等字符串处理函数
  3. 列表
    1. max
    2. min
    3. length
    4. first
    5. sort
    6. unique
    7. reverse
    8. 下标取值
  4. 字典
    1. dict2items
    2. items2dict

4. 特殊处理过滤器

  1. 密码过滤器
    • hash
    • password_hash
  2. 二进制与编码的转换
    • b64decode
    • b64encode

5. 复杂数据格式处理

  1. json_query
  2. to_json, to_yaml,to_nice_json, to_nice_yaml
  3. from_json, from_yaml

6. 万能处理插件 Lookup / query

  1. file
  2. template
  3. pipe
  4. lines
  5. url
  6. password

7. 可迭代对象(列表,字典,嵌套数据)

  1. with_xxx 和 loop 可进行相互替代
  2. with_item 和 loop + flatten
  3. with_subelements 和 loop + subelements
  4. with_fileglob 和 loop + fileglob
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值