Add Ansible version to a job's Zuul vars
The Ansible version is sometimes used for selecting the correct linter or for implementing feature switches to make roles/playbooks backward compatible. With the split of Ansible into an "ansible" and "ansible-core" package, the `ansible_version` now contains the version of the core package. There seems to be no other variable that contains the version of the "Ansible community" package that Zuul is using. In order to support this use-case for Ansible 5+ we will add the Ansible version to the job's Zuul vars. Change-Id: I3f3a3237b8649770a9b7ff488e501a97b646a4c4
This commit is contained in:
@ -332,6 +332,11 @@ of item.
|
||||
connectivity issues then previous attempts may have been cancelled,
|
||||
and this value will be greater than 1.
|
||||
|
||||
.. var:: ansible_version
|
||||
|
||||
The version of the Ansible community package release used for executing
|
||||
the job.
|
||||
|
||||
.. var:: project
|
||||
|
||||
The item's project. This is a data structure with the following
|
||||
|
@ -104,6 +104,7 @@ class TestInventoryGithub(TestInventoryBase):
|
||||
z_vars = inventory['all']['vars']['zuul']
|
||||
self.assertIn('executor', z_vars)
|
||||
self.assertIn('src_root', z_vars['executor'])
|
||||
self.assertIn('ansible_version', z_vars)
|
||||
self.assertIn('job', z_vars)
|
||||
self.assertIn('event_id', z_vars)
|
||||
self.assertEqual(z_vars['job'], 'single-inventory')
|
||||
@ -137,6 +138,7 @@ class TestInventoryPythonPath(TestInventoryBase):
|
||||
z_vars = inventory['all']['vars']['zuul']
|
||||
self.assertIn('executor', z_vars)
|
||||
self.assertIn('src_root', z_vars['executor'])
|
||||
self.assertIn('ansible_version', z_vars)
|
||||
self.assertIn('job', z_vars)
|
||||
self.assertEqual(z_vars['job'], 'single-inventory')
|
||||
self.assertEqual(z_vars['message'], 'QQ==')
|
||||
@ -167,6 +169,7 @@ class TestInventoryShellType(TestInventoryBase):
|
||||
z_vars = inventory['all']['vars']['zuul']
|
||||
self.assertIn('executor', z_vars)
|
||||
self.assertIn('src_root', z_vars['executor'])
|
||||
self.assertIn('ansible_version', z_vars)
|
||||
self.assertIn('job', z_vars)
|
||||
self.assertEqual(z_vars['job'], 'single-inventory')
|
||||
self.assertEqual(z_vars['message'], 'QQ==')
|
||||
@ -195,6 +198,7 @@ class TestInventoryAutoPython(TestInventoryBase):
|
||||
self.assertIn('executor', z_vars)
|
||||
self.assertIn('src_root', z_vars['executor'])
|
||||
self.assertIn('job', z_vars)
|
||||
self.assertEqual(z_vars['ansible_version'], '2.8')
|
||||
self.assertEqual(z_vars['job'], 'ansible-version28-inventory')
|
||||
self.assertEqual(z_vars['message'], 'QQ==')
|
||||
|
||||
@ -219,6 +223,7 @@ class TestInventoryAutoPython(TestInventoryBase):
|
||||
self.assertIn('executor', z_vars)
|
||||
self.assertIn('src_root', z_vars['executor'])
|
||||
self.assertIn('job', z_vars)
|
||||
self.assertEqual(z_vars['ansible_version'], '2.9')
|
||||
self.assertEqual(z_vars['job'], 'ansible-version29-inventory')
|
||||
self.assertEqual(z_vars['message'], 'QQ==')
|
||||
|
||||
@ -243,6 +248,7 @@ class TestInventoryAutoPython(TestInventoryBase):
|
||||
self.assertIn('executor', z_vars)
|
||||
self.assertIn('src_root', z_vars['executor'])
|
||||
self.assertIn('job', z_vars)
|
||||
self.assertEqual(z_vars['ansible_version'], '5')
|
||||
self.assertEqual(z_vars['job'], 'ansible-version5-inventory')
|
||||
self.assertEqual(z_vars['message'], 'QQ==')
|
||||
|
||||
|
@ -2443,6 +2443,7 @@ class AnsibleJob(object):
|
||||
work_root=self.jobdir.work_root,
|
||||
result_data_file=self.jobdir.result_data_file,
|
||||
inventory_file=self.jobdir.inventory)
|
||||
zuul_vars['ansible_version'] = self.ansible_version
|
||||
|
||||
# Add playbook_context info
|
||||
zuul_vars['playbook_context'] = dict(
|
||||
|
Reference in New Issue
Block a user