Installing specific apt version with ansible
Asked Answered
F

2

28

I used an ansible playbook to install git:

---
- hosts: "www"
  tasks:
  - name: Update apt repo
    apt: update_cache=yes
  - name: Install dependencies
    apt: name={{item}} state=installed
    with_items:
      - git

I checked the installed versions:

$ git --version
git version 1.9.1

But adding these to the ansible playbook: apt: name=git=1.9.1 state=installed

and rerunning results in the following error:

fatal: [46.101.94.110]: FAILED! => {"cache_update_time": 0, "cache_updated": false, "changed": false, "failed": true, "msg": "'/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" install 'git=1.9.1'' failed: E: Version '1.9.1' for 'git' was not found\n", "stderr": "E: Version '1.9.1' for 'git' 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..."]}

Fiber answered 22/3, 2016 at 9:17 Comment(0)
N
41

Git package with that specific version is as follows:

git=1:1.9.1-1ubuntu0.2

Your task should be:

apt: name=git=1:1.9.1-1ubuntu0.2 state=present

Regards

Nadanadab answered 22/3, 2016 at 10:14 Comment(1)
Yes brilliant. I used dpkg -s git to find the version ( 1:1.9.1-1ubuntu0.3 in my case).Fiber
M
9

You don't need two tasks for updating cache and installing. Your playbook should look like:

---
- hosts: "www"
  tasks:
  - name: Install dependencies
    apt:
      name:
        - git=1:1.9.1-1ubuntu0.2
      state: installed
      update_cache: yes

note that Ansible supports wildcarding so you don't necessarily need the full version string

Mage answered 22/3, 2016 at 16:22 Comment(2)
Hey thanks @smiller171 . The cache update can sometimes take a long time so I just keep it separate as a way of understanding how the Ansible script is progressing and where any failure/problem might lie. Regarding the wildcarding, would something like: - git=*1.9.1* work?Fiber
I don't think I've used the wildcarding myself, was just seeing it in the docs. Best way to find out is to run a quick testMage

© 2022 - 2024 — McMap. All rights reserved.