简体   繁体   中英

Apt-get update error on ubuntu 16.04 by using Ansible playbook

I have written ansible playbook for installing the docker on Ubuntu 16.04 LTS. While running the ansible playbook, I am getting apt-get update error

I have tried running the attached playbook code.

      - hosts: docker
        become: yes
        become_user: root
        tasks:
           - name: apt-get update
             shell: apt-get update -y
           - name: Install packages to allow apt to use a repository   overHTTPS
             shell: sudo apt-get install -y \
                    apt-transport-https -y \
                    ca-certificates \
                    curl \
                    gnupg-agent \
                    software-properties-common
           - name: Add Docker’s official GPG key
             shell: curl -fsSL    https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
           - name: Use the following command to set up the stable repository
             shell: add-apt-repository \
                    "deb [arch=amd64]   https://download.docker.com/linux/ubuntu\
                    $(lsb_release -cs) \
                    stable"
           - name: apt update
             shell: apt-get update -y
           - name: Installing the docker 17.03.0
             shell: apt-get install docker-ce=18.06.1~ce-3-0~ubuntu -y

Before installing the docker, I try to update the ubuntu server, but I am getting below error

          TASK [apt update]      **************************************************************
         fatal: [localhost]: FAILED! => {"changed": true, "cmd": "apt-         get update -y", "delta": "0:00:12.338257",
         "end": "2019-04-02 11:58:13.377956", "failed": true, "rc":   100, "start": "2019-04-02 11:58:01.039699",
          "stderr": "W: The repository   'https://download.docker.com/linux/ubuntu\\ xenial Release' does not    have
          a Release file.\nE: Failed to fetch    https://download.docker.com/linux/ubuntu\\/dists/xenial/\\/binary-
         amd64/Packages  404  Not Found\nE: Some index files failed to   download. They have been ignored, or old 
         ones used instead.", "stdout": "Hit:1 http://us-  east1.gce.archive.ubuntu.com/ubuntu xenial InRelease\nH
         it:2 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial- updates InRelease\nHit:3 http://us-east1.gce.
         archive.ubuntu.com/ubuntu xenial-backports InRelease\nHit:4   http://archive.canonical.com/ubuntu xenial 
         InRelease\nHit:5 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial InRelease\nHit:6   http://securit
         y.ubuntu.com/ubuntu xenial-security InRelease\nIgn:7   https://download.docker.com/linux/ubuntu\\ xenial 
         InRelease\nIgn:8 https://download.docker.com/linux/ubuntu\\   xenial Release\nIgn:9 https://download.dock
        er.com/linux/ubuntu\\ xenial/\\ amd64 Packages\nIgn:10 https://download.docker.com/linux/ubuntu\\ xenia
        l/\\ all Packages\nIgn:11   https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-  en_US\nIgn:1
        2 https://download.docker.com/linux/ubuntu\\ xenial/\\   Translation-en\nIgn:13 https://download.docker.c
        om/linux/ubuntu\\ xenial/stable amd64 Packages\nIgn:14 https://download.docker.com/linux/ubuntu\\ xenia
        l/stable all Packages\nIgn:15   https://download.docker.com/linux/ubuntu\\ xenial/stable Translation-  en_U
         S\nIgn:16 https://download.docker.com/linux/ubuntu\\   xenial/stable Translation-en\nIgn:9 https://downlo
         ad.docker.com/linux/ubuntu\\ xenial/\\ amd64 Packages\nIgn:10    https://download.docker.com/linux/ubuntu\
         \ xenial/\\ all Packages\nIgn:11   https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-en_US
          \nIgn:12 https://download.docker.com/linux/ubuntu\\ xenial/\\     Translation-en\nIgn:13 https://download.d
         ocker.com/linux/ubuntu\\ xenial/stable amd64 Packages\nIgn:14   https://download.docker.com/linux/ubuntu\
         \ xenial/stable all Packages\nIgn:15     https://download.docker.com/linux/ubuntu\\ xenial/stable Translati
        on-en_US\nIgn:16 https://download.docker.com/linux/ubuntu\\    xenial/stable Translation-en\nIgn:9 https:/
        /download.docker.com/linux/ubuntu\\ xenial/\\ amd64      Packages\nIgn:10 https://download.docker.com/linux/
        ubuntu\\ xenial/\\ all Packages\nIgn:11    https://download.docker.com/linux/ubuntu\\ xenial/\\ Translatio
         n-en_US\nIgn:12 https://download.docker.com/linux/ubuntu\\  xenial/\\ Translation-en\nIgn:13 https://dow
         nload.docker.com/linux/ubuntu\\ xenial/stable amd64    Packages\nIgn:14 https://download.docker.com/linux/
       ubuntu\\ xenial/stable all Packages\nIgn:15 https://download.docker.com/linux/ubuntu\\ xenial/stable Tr
        anslation-en_US\nIgn:16 https://download.docker.com/linux/ubuntu\\ xenial/stable Translation-en\nIgn:9 
       https://download.docker.com/linux/ubuntu\\ xenial/\\ amd64 Packages\nIgn:10 https://download.docker.com
      /linux/ubuntu\\ xenial/\\ all Packages\nIgn:11  https://download.docker.com/linux/ubuntu\\ xenial/\\ Tra
      nslation-en_US\nIgn:12 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-en\nIgn:13 http
        s://download.docker.com/linux/ubuntu\\ xenial/stable amd64  Packages\nIgn:14 https://download.docker.com
     /linux/ubuntu\\ xenial/stable all Packages\nIgn:15

You have many mistakes in your shell commands:

  • 2 -y in your apt-get install command
  • a mix of \\ and " in your shell commands

But more importantly, you should avoid to use shell module when a module that do the job exists, and in your case, you can use 3 modules:

Something like should work:

- hosts: docker
  become: yes

  tasks:

    - name: Update repositories cache and install packages
      apt:
        name: apt-transport-https ca-certificates curl gnupg-agent software-properties-common
        update_cache: yes

    - name: Add Docker PGP key
      apt_key:
        url: https://download.docker.com/linux/ubuntu/gpg
        state: present

    - name: Add docker apt repository
      apt_repository:
        repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu ... stable"
        state: present

    - name: Update repositories cache and install packages
      apt:
        name: docker-ce
        update_cache: yes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM