Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible apt-get install output

I am using vagrant with an ansible playbook to automatically install a bunch of programs on an ubuntu image. One program is failing to install on the vagrant VM. In the Vagrant file I have

config.vm.provision :ansible do |ansible|
  ansible.verbose = "vvv"
  ansible.playbook = "provisioning/playbook.yml"
end

but the verbose output does not include the apt-get output. My playbook.yml looks like

---
- hosts: all
  sudo: true
  tasks:
    - name: get vi
      apt: state=latest name=vim  

How can I see the console output of an individual (or all) apt-get install's on the VM since ansible instead outputs each install in the format

TASK: [Install vim] *********************************************************** 
failed: [default] => {"failed": true}
...
like image 353
myol Avatar asked Dec 01 '15 17:12

myol


People also ask

What is Update_cache?

update_cache=yes tells Ansible's apt module to refresh the caches before applying whatever change is necessary (if any).

What is Ansible apt?

APT stands for "Advanced Packaging Tool" is the preferred package management toolset in Ubuntu. It allows us to install new packages, update them, and remove the packages from Ubuntu or Debian systems.

How do I know if Ansible package is installed?

Check: ... TASK [test : Check if NGINX is installed] **** ok: [ssh.dev.rtfm.co.ua] TASK [test : NGINX test result] **** ok: [ssh.dev.rtfm.co.ua] => { "msg": "NGINX found" } TASK [test : NGINX test result] **** skipping: [ssh.dev.rtfm.co.ua] PLAY RECAP **** ssh.dev.rtfm.co.ua : ok=3 changed=0 unreachable=0 failed=0 ...


1 Answers

Reproducing the stdout of apt

Here is how to reproduce the stdout of apt

---
- name: 'apt: update & upgrade'
  apt:
    update_cache: yes
    cache_valid_time: 3600
    upgrade: safe
  register: apt
- debug: msg={{ apt.stdout.split('\n')[:-1] }}

…with nice line breaks, thanks to .split('\n'), and omitting the last empty string with [:-1], all of which is Python string manipulation, of course.

"msg": [
    "Reading package lists...", 
    "Building dependency tree...", 
    "Reading state information...", 
    "Reading extended state information...", 
    "Initializing package states...", 
    "Building tag database...", 
    "No packages will be installed, upgraded, or removed.", 
    "0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", 
    "Need to get 0 B of archives. After unpacking 0 B will be used.", 
    "Reading package lists...", 
    "Building dependency tree...", 
    "Reading state information...", 
    "Reading extended state information...", 
    "Initializing package states...", 
    "Building tag database..."
]
like image 84
Serge Stroobandt Avatar answered Sep 28 '22 06:09

Serge Stroobandt