Open akira6592 opened 2 years ago
Any updates for this?
Could be related #14868
just chiming in as the OP of https://github.com/ansible/awx/issues/14868
I think this feature enhancement would be for ansible its self, not specifically AWX?
@j-oss2023
I think AWX specific.
In ansible-playbook command, the value of a variable given by the -e option can be used in the netbox.nebox.nb_inventory inventory plugin.
@akira6592 ineresting...
I made a custom dynamic plugin
https://github.com/j-oss2023/mysql-dynamic-inventory
And I'm unable to pass extra var to it ansible or awx ,
this gives me a clue that netbox inventory plugin is doing some extra stuff
Thanks !!!
I will investigate and fix my plugin so that it accepts extra var (if I can)
Fixed my dynamic inventory plugin
But - yes I am still experiencing the same exact issue when running it in AWX...
Works perfectly on cli - as per this example: https://github.com/ansible/awx/issues/14868#issuecomment-1945208879
But not in AWX :(
Maybe it is the same as in my case.
@akira6592
Yes, you're absolutely right - and thank you for your comment, you gave me a clue to fix my dynamic plugin - which now correctly uses -e, --extra-vars
def parse(self, inventory, loader, path, cache=True):
'''Parses the inventory file'''
super(InventoryModule, self).parse(inventory, loader, path, cache)
self._read_config_data(path)
self.templar.available_variables = self._vars
for option in self._options:
try:
if self.get_option(option):
templated_option = self.templar.template(self.get_option(option))
self.set_option(option, templated_option)
except Exception as e:
raise AnsibleError(f"Error processing templating for {option}: {str(e)}")
self._fetch_hosts()
As you stated, this is an AWX problem,
ansible works fine from CLI
@akira6592
Perhaps you are willing to implement this change - help me to figure out where it is, reverse engineer the awx repo
This is what podman reveals as the command for the inventory sync job:
ansible-inventory --list --export -i /runner/project/dynamic/all-mysql.yml --output /runner/artifacts/1842/output.json --playbook-dir /runner/project/dynamic -vvv
This is what podman reveals as the command for the playbook job:
ssh-agent sh -c trap 'rm -f /runner/artifacts/1845/ssh_key_data' EXIT && ssh-add /runner/artifacts/1845/ssh_key_data && rm -f /runner/artifacts/1845/ssh_key_data && ansible-playbook -u root -l myhost -i /runner/inventory -e @/runner/env/extravars myplaybook.yml
As you can see, the invocation of the inventory sync job omits the -e @/runner/env/extravars
part - which is why we are having the issue we are having...
I'll start to debug / reverse engineer - see if i can make it sing...
If you have time to work on this let me know, Keen to implement and push a conformed fix 👍
OK, i think its in awx/awx/main/tasks/jobs.py
BaseTask._write_extra_vars_file
is involved...
and is called in classes RunJob
, RunProjectUpdate
and RunAdHocCommand
within a function build_extra_vars_file
Still digging, but getting warmer
I'm by not means claiming to understand the wider implications of this, but gonna give it a good crack - see what i can do (with the help of ChatGPT)
Update on progress...
Yeah - not going to be able to fix this... 📦
there's a lot to consider and change
The models: inventory, mixins ? the tasks: inventory
I'm probably only scratching the surface
Please confirm the following
Feature type
Enhancement to Existing Feature
Feature Summary
I would like to be able to reflect the values of additional variables (including surveys) in job templates and workflow job templates in the inventory source yaml.
The netbox.nebox.nb_inventory inventory plugin will be available in the next release with several filter options for extra vars. The purpose is to improve performance.
More info: https://github.com/netbox-community/ansible_modules/pull/834
In ansible-playbook command, the value of a variable given by the -e option can be used in the netbox.nebox.nb_inventory inventory plugin.
However, in AWX, the value of the variable does not seem to be passed on because the -e option is missing from the ansible-inventory command when retrieving the inventory. https://github.com/ansible/awx/blob/21.7.0/awx/main/tasks/jobs.py#L1506-L1539
Select the relevant components
Steps to reproduce
site
variable value via SurveyCurrent results
The following error message appears on Inventory Sync.
Sugested feature result
Additional information
n/a