Think before you speak, read before you think.

ansible 读取 yaml facts

by

in

默认 ansible 只读取 /etc/ansible/facts.d/*.fact,并且是 ini, json,或者执行能输出 json.

对于机器上放了 env.yaml ,想要塞入 facts,可以做一个脚本,输出 json

#!/usr/bin/env python
#-*- utf-8 -*-

import yaml
import json

env_dict = yaml.load(open('/etc/env.yaml'))
print json.dumps(env_dict)
ansible all -i hosts -l guest1 -m setup -a "filter=ansible_local"

这样可以直接在 playbook 里用 ansible_local.env.cluster_name 变量了



Comments

Leave a Reply

Your email address will not be published. Required fields are marked *