Ansible: Access host/group vars from within custom module

前端 未结 2 927
面向向阳花
面向向阳花 2020-12-18 23:39

Is there a way how one can access host/group vars from within a custom written module? I would like to avoid to pass all required vars as module parameters.

My modul

2条回答
  •  别那么骄傲
    2020-12-19 00:30

    I think you pretty much hit the nail on the head with your thinking here:

    I guess it is not possible, since the module runs on the target machine and probably the facts/host/group vars are not transferred along with the module...

    However, having said that, if you really have a need for this then there might be a slightly messy way of doing it. As of Ansible 1.8 you can set up fact caching, which uses redis to cache facts between runs of plays. Since redis is pretty easy to use and has clients for most popular programming languages, you could have your module query the redis server for any facts you need. It's not exactly the cleanest way to do it, but it just might work.

提交回复
热议问题