I am using chef inspc to verify the the AMI Images created using packer to fit out standards. One of the requirement is checking the version difference between AMI images.
I have the following code which checks for ansible version 2.8.
control 'Ansible check' do
impact 1.0
title 'Check anisble is installed'
describe package('ansible') do
it { should be_installed }
its('version') { should match (/2.8.*/) }
end
end
However I need to get the full version variable to check difference between AMIs. Ex 2.8.8
Is there a way to get the version variable outputted in the inspec report function or do I have to use another tools to do this?
Thanks in advance.
Using this post https://discourse.chef.io/t/customise-testing-report/11722/4, I setuped a simple hack to write the version to a another text file using ruby.
Below is my code.
f = File.open('versions.txt', 'a')
control 'Ansible check' do
impact 1.0
title 'Check anisble is installed'
describe package('ansible') do
it { should be_installed }
its('version') { should match (/2.8.*/) }
f.write("ansible : ", packages('ansible').versions[0], "\n")
end
end
The version file output as below
# cat versions.txt
ansible : 2.8.10+dfsg-1