Rituparno Bhattacharya
Rituparno Bhattacharya

Reputation: 363

Issue with Ansible Playbook in Ubuntu

I am trying to create a Ansible playbook. Below is the code of the playbook I have created.

---
- name: "Install Packages"
  hosts: localhost
  connection: local
  become: yes
  tasks:

  - name: Fix problems with packages
    shell: sudo dpkg --configure -a

  - name: Run apt-get install
    shell: sudo apt-get install -f

  - name: Clean & Update
    shell: sudo apt-get clean && sudo apt-get update

  - name: Upgrade
    shell: sudo apt-get upgrade -y

  - name: Install packages
    apt:
      name:
      - python3-pip
      - apache2
      - libapache2-mod-wsgi-py3
      - mysql-server
      - libmysqlclient-dev
      - apt-transport-https
      - erlang-base
      - erlang-asn1
      - erlang-crypto
      - erlang-eldap
      - erlang-ftp
      - erlang-inets
      - erlang-mnesia
      - erlang-os-mon
      - erlang-parsetools
      - erlang-public-key
      - erlang-runtime-tools
      - erlang-snmp
      - erlang-ssl
      - erlang-syntax-tools
      - erlang-tftp
      - erlang-tools
      - erlang-xmerl
      - rabbitmq-server
      state: latest
      cache_valid_time: 3600 

While running this playbook, I am getting below mentioned error -

    [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
    
    PLAY [Install Packages] *********************************************************************************************************************************************************************
    
    TASK [Gathering Facts] **********************************************************************************************************************************************************************
    ok: [localhost]
    
    TASK [Fix problems with packages] ***********************************************************************************************************************************************************
    [WARNING]: Consider using 'become', 'become_method', and 'become_user' rather than running sudo
    changed: [localhost]
    
    TASK [Run apt-get install] ******************************************************************************************************************************************************************
    changed: [localhost]
    
    TASK [Clean & Update] ***********************************************************************************************************************************************************************
    changed: [localhost]
    
    TASK [Upgrade] ******************************************************************************************************************************************************************************
    changed: [localhost]
    
    TASK [Install packages] *********************************************************************************************************************************************************************
    fatal: [localhost]: FAILED! => {"cache_update_time": 1597472721, "cache_updated": false, "changed": false, "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"      install 'python3-pip' 'apache2' 'libapache2-mod-wsgi-py3' 'mysql-server' 'libmysqlclient-dev' 'apt-transport-https' 'erlang-base' 'erlang-asn1' 'erlang-crypto' 'erlang-eldap' 'erlang-ftp' 'erlang-inets' 'erlang-mnesia' 'erlang-os-mon' 'erlang-parsetools' 'erlang-public-key' 'erlang-runtime-tools' 'erlang-snmp' 'erlang-ssl' 'erlang-syntax-tools' 'erlang-tftp' 'erlang-tools' 'erlang-xmerl' 'rabbitmq-server'' failed: E: Unable to correct problems, you have held broken packages.\n", "rc": 100, "stderr": "E: Unable to correct problems, you have held broken packages.\n", "stderr_lines": ["E: Unable to correct problems, you have held broken packages."], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nSome packages could not be installed. This may mean that you have\nrequested an impossible situation or if you are using the unstable\ndistribution that some required packages have not yet been created\nor been moved out of Incoming.\nThe following information may help to resolve the situation:\n\nThe following packages have unmet dependencies:\n erlang-ftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or\n                       erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed\n              Depends: erlang-runtime-tools (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed\n              Depends: erlang-ssl (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed\n erlang-tftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or\n                        erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "Some packages could not be installed. This may mean that you have", "requested an impossible situation or if you are using the unstable", "distribution that some required packages have not yet been created", "or been moved out of Incoming.", "The following information may help to resolve the situation:", "", "The following packages have unmet dependencies:", " erlang-ftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or", "                       erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed", "              Depends: erlang-runtime-tools (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed", "              Depends: erlang-ssl (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed", " erlang-tftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or", "                        erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed"]}
    
    PLAY RECAP **********************************************************************************************************************************************************************************
    localhost                  : ok=5    changed=4    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

> fatal: [localhost]: FAILED! => {"cache_update_time": 1597472721, cache_updated": false, "changed": false, "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\" install 'python3-pip' 'apache2' 'libapache2-mod-wsgi-py3' 'mysql-server' 'libmysqlclient-dev' 'apt-transport-https' 'erlang-base' 'erlang-asn1' 'erlang-crypto' 'erlang-eldap' 'erlang-ftp' 'erlang-inets' 'erlang-mnesia' 'erlang-os-mon' 'erlang-parsetools' 'erlang-public-key' 'erlang-runtime-tools' 'erlang-snmp' 'erlang-ssl' 'erlang-syntax-tools' 'erlang-tftp' 'erlang-tools' 'erlang-xmerl' 'rabbitmq-server'' failed: E: Unable to correct problems, you have held broken packages.\n", "rc": 100, "stderr": "E: Unable to correct problems, you have held broken packages.\n", "stderr_lines": ["E: Unable to correct problems, you have held broken packages."], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nSome packages could not be installed. This may mean that you have\nrequested an impossible situation or if you are using the unstable\ndistribution that some required packages have not yet been created\nor been moved out of Incoming.\nThe following information may help to resolve the situation:\n\nThe following packages have unmet dependencies:\n erlang-ftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or\n erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed\n Depends: erlang-runtime-tools (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed\n Depends: erlang-ssl (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed\n erlang-tftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or\n erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "Some packages could not be installed. This may mean that you have", "requested an impossible situation or if you are using the unstable", "distribution that some required packages have not yet been created", "or been moved out of Incoming.", "The following information may help to resolve the situation:", "", "The following packages have unmet dependencies:", " erlang-ftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or", " erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed", " Depends: erlang-runtime-tools (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed", " Depends: erlang-ssl (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed", " erlang-tftp : Depends: erlang-base (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but 1:20.2.2+dfsg-1ubuntu2 is to be installed or", " erlang-base-hipe (= 1:22.0.7+dfsg-1build1~ubuntu18.04.1) but it is not going to be installed"]}

Unable to undertsand how to fix this issue. I am running Ubuntu as Hyper-V guest. Do I need to separate "elang" part from the apt section and try to run with apt-get?

My O/S version - Ubuntu 18.04.3 LTS


UPDATE:

After few googling, I found I was trying to install RabbitMQ Server & erlang in a wrong way for Ubuntu 18.04.3 LTS. Hence I modified my Ansible Playbook like below. Posting here updated playbook code in case someone needs in future.

---
- name: "Install Packages"
  hosts: localhost
  connection: local
  become: yes
  tasks:

  - name: Install basic packages
    apt:
      name:
      - vim
      - curl
      - python3-pip
      - apache2
      - libapache2-mod-wsgi-py3
      - mysql-server
      - libmysqlclient-dev
      state: latest
      cache_valid_time: 3600

  - name: Curl for RabbitMQ
    shell: curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -

  - name: Add an apt key by id from a keyserver
    apt_key:
      keyserver: hkps://keys.openpgp.org
      id: 0A9AF2115F4687BD29803A206B73A36E6026DFCA

  - name: Install transport http
    apt:
      name:
      - apt-transport-https
      state: latest
      cache_valid_time: 3600

  - name: Insert/Update /etc/apt/sources.list.d/bintray.erlang.list file
    blockinfile:
      path: /etc/apt/sources.list.d/bintray.erlang.list
      block: |
        # >>> Bionic version is for ubuntu 18.04
        # This repository provides Erlang packages produced by the RabbitMQ team
        # See below for supported distribution and component values
        deb https://dl.bintray.com/rabbitmq-erlang/debian bionic erlang
      create: yes

  - name: Update apt-get repo and cache
    apt: update_cache=yes force_apt_get=yes cache_valid_time=3600

  - name: Install erlang packages
    apt:
      name:
      - erlang-base
      - erlang-asn1
      - erlang-crypto
      - erlang-eldap
      - erlang-ftp
      - erlang-inets
      - erlang-mnesia
      - erlang-os-mon
      - erlang-parsetools
      - erlang-public-key
      - erlang-runtime-tools
      - erlang-snmp
      - erlang-ssl
      - erlang-syntax-tools
      - erlang-tftp
      - erlang-tools
      - erlang-xmerl
      state: latest
      cache_valid_time: 3600

  - shell: echo "deb https://dl.bintray.com/rabbitmq/debian bionic main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list
    register: echoout
  - debug: msg="the echo was {{ echoout.stdout }}"

  - name: Update apt-get repo and cache
    apt: update_cache=yes force_apt_get=yes cache_valid_time=3600

  - name: Install RabbitMQ Server
    apt:
      name:
      - rabbitmq-server
      state: latest
      cache_valid_time: 3600

  - name: start & enable RabbitMQ Server
    service:
      name=rabbitmq-server
      state=started
      enabled=yes

  - name: checking RabbitMQ Server status
    command: systemctl status "{{ item }}"
    with_items:
    - rabbitmq-server
    register: result
    ignore_errors: yes

  - name: showing RabbitMQ Server status
    debug:
     var: result

Thanks for your help & supoort. Mark the status as SOLVED.

Upvotes: 1

Views: 3661

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 67959

failed: E: Unable to correct problems, you have held broken packages.\n", "rc": 100

A: It seems that you've marked to hold broken packages. List the packages "on hold"

shell> sudo apt-mark showhold

and cancel the set hold on broken packages. Make sure you know what you're doing if you keep any packages "on hold"

shell> sudo apt-mark unhold {package}

Now, manually, try the shell commands from your playbook to fix, resolve, update, and upgrade. Try Ansible when the packaging is working again from the command line.


It's possible to manage selections by Ansible module dpkg_selections choices: install, hold, deinstall, purge.

Upvotes: 2

Related Questions