Я попытался написать сценарий инвентаризации Dynami c в python, который выглядит следующим образом:
[root@satellite code]# python3 dynamic_inventory.py --list > hosts
[root@satellite code]# cat hosts
{"k8s-master": ["k8s-master.example.com"], "k8s-worker": ["worker-1.example.com", "worker-2.example.com"], "satellite": ["satellite.example.com"], "all": ["satellite.example.com", "worker-2.example.com", "k8s-master.example.com", "worker-1.example.com"], "Centos7": ["k8s-master.example.com", "worker-1.example.com", "worker-2.example.com", "satellite.example.com"]}
Теперь, когда я пытаюсь использовать инвентарь, я получаю следующие ошибки:
[root@satellite code]# ansible-playbook -i hosts sample.yaml
[WARNING]: Skipping 'Centos7' as this is not a valid group definition
[WARNING]: Skipping 'k8s-worker' as this is not a valid group definition
[WARNING]: Skipping 'satellite' as this is not a valid group definition
[WARNING]: Skipping 'k8s-master' as this is not a valid group definition
[WARNING]: Skipping 'all' as this is not a valid group definition
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [all] *************************************************************************************************************************************************************
skipping: no hosts matched
PLAY RECAP *************************************************************************************************************************************************************
Тоже пробовал:
[root@satellite code]# ansible-playbook -i dynamic_inventory.py sample.yaml
[WARNING]: * Failed to parse /root/code/dynamic_inventory.py with ini plugin: /root/code/dynamic_inventory.py:1: Expected key=value host variable assignment, got: os
[WARNING]: Unable to parse /root/code/dynamic_inventory.py as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [all] *************************************************************************************************************************************************************
skipping: no hosts matched
PLAY RECAP *************************************************************************************************************************************************************
Скрипт извлекает имена хостов из MySQL DB в формат JSON. Я не нашел никаких плагинов в официальных документах ansible. Может ли кто-нибудь помочь, как go об этом? Есть ли способ отобразить вывод скрипта в формате ini.