Hi,
I am developing a new Ansible collection to manage configuration of network devices. These devices are configured only over API. I need to be able to define them in an inventory file. From my understanding, I should create a new connection plugin and use it to connect to devices.
The problem starts when I try to access values for my connection plugin configuration options. These values are device-specific so it would be best to define them in an inventory file.
When I run a playbook that uses config_module I am getting an error:
fatal: [device_1]: FAILED! => {“msg”: "No setting was provided for required configuration plugin_type: connection plugin: plugin_name setting: address "}
I am running Ansible 8.2 [ansible-core 2.15.2]
I’ve noticed that my other calls to self.get_option(option) always return default value from connection plugin documentation irrespective of what is defined in the inventory file. I’ve checked that these inventory variables are available at playbook level. I am able to use debug module to print their values.
How do I access inventory variables for a given host in my connection plugin?
It seems to have been possible in Ansible 2.9
I could pass them from the playbook to config_module as arguments and define ansible_connection: local for each device in inventory but it:
- raises separation of concerns issue (module for configuration should not care about connection details)
- adds additional arguments for each task with configuration module (there will be many in a playbook)
- means that the connection will not be persistent between tasks
Any ideas?
Best Regards
Piotr Gabryś