Specifying version when installing Apache

I’m thinking of using specific versions for everything whenever I can. This would enable me to mirror exactly what I have in one server to another at any given time.

With that said, I tried a very basic install of Apache and attempted to see what it took to get this configured.

I started with:

tasks:

  • name: install apache2
    apt: name=apache2 state=installed update_cache=yes
    notify: start apache2

Then, to see the version installed:

me@server:~$ apache2 -v
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2016-07-14T12:32:26

I figure, I should just specify the version in my playbook:

tasks:

  • name: install apache2
    apt: name=apache2=2.4.18 state=installed update_cache=yes
    notify: start apache2

The error when I run the playbook:

TASK [install apache2] *********************************************************
fatal: [192.168.2.33]: FAILED! => {“cache_update_time”: 1491508623, “cache_updated”: true, “changed”: false, “failed”: true, “msg”: “‘/usr/bin/apt-get -y -o "Dpkg::Options::=–force-confdef" -o "Dpkg::Options::=–force-confold" install ‘apache2=2.4.18’’ failed: E: Version ‘2.4.18’ for ‘apache2’ was not found\n”, “stderr”: “E: Version ‘2.4.18’ for ‘apache2’ was not found\n”, “stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\n”, “stdout_lines”: [“Reading package lists…”, “Building dependency tree…”, “Reading state information…”]}

If you run a "apt-cache show apache2 | grep Version" you'll see that the version is longer, something like "2.4.18-2ubuntu3.1"

You'll need to specify the entire string or use wildcard, read more about wildcard in the comments to name here
https://docs.ansible.com/ansible/apt_module.html#options