testinfraでは、 testinfra.modules.ansible.Ansibleget_variables()
のメソッドを使用して
いますが、 testinfraは私の Ansible 変数を評価できないようです。
私のポックについて説明しましょう。
~/tmp/ansible-testinfra
├── inventories
│ ├── group_vars
│ │ └── all.yml
│ └── inventory.ini
└── test_simple.py
私は2つの変数を定義しました:
# inventories/group_vars/all.yml
---
one: "value one"
two: "{{ one }} and value two"
myinventory.ini
は単純な localhost です:
# inventories/inventory
[all]
localhost
次のような非常に単純なテストを作成しました。
# test_simple.py
import pprint
def test_print_variables(host):
pprint.pprint(host.ansible.get_variables())
def test_variables(host):
my_vars = host.ansible.get_variables()
assert my_vars['two'] == 'value one and value two'
pytest を実行すると、ここに私の sdtout があります:
~/tmp/ansible-testinfra$ pytest --hosts "ansible://all?ansible_inventory=inventories/inventory.ini" -s --tb=no
============================================================================ test session starts ============================================================================
platform linux -- Python 3.6.9, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /home/olhoa/tmp/ansible-testinfra
plugins: testinfra-6.1.0
collected 2 items
test_simple.py {'group_names': ['ungrouped'],
'groups': {'all': ['localhost'], 'ungrouped': ['localhost']},
'inventory_hostname': 'localhost',
'one': 'value one',
'two': '{{ one }} and value two'}
.F
========================================================================== short test summary info ==========================================================================
FAILED test_simple.py::test_variables[ansible://localhost] - AssertionError: assert '{{ one }} and value two' == 'value one and value two'
ご覧のとおり、 variableone
で使用された場合、 variable は解釈されませんtwo
。
それで、これを行うことは可能ですか?
ご意見ありがとうございます !:)