Ubuntu中Ansible Playbook的问题

Ubuntu中Ansible Playbook的问题,ubuntu,ansible,Ubuntu,Ansible,我正在尝试创建一个Ansible剧本。下面是我创建的剧本的代码 --- - 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:

我正在尝试创建一个Ansible剧本。下面是我创建的剧本的代码

---
- 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 
在运行这个剧本时,我遇到了下面提到的错误-

    [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

>致命:[localhost]:失败!=>{“缓存更新时间”:1597472721, 缓存更新:false,“更改”:false,“msg”:“'/usr/bin/apt get-y-o\”Dpkg::Options:=--force confdef\”-o\“Dpkg::Options:=--force confold\”安装“python3 pip”“apache2”“libapache2-mod-wsgi-py3”“mysql服务器”“libmysqlclient dev”“apt传输https”“erlang base”“erlang-asn1”“erlang加密”“erlang eldap”“erlang ftp”“erlang iNet”“erlang mnesia”“erlang os mon”“erlang解析工具”“erlang公钥”“erlang运行时工具”“erlang snmp”“erlang ssl”“erlang语法ls''erlang tftp''erlang tools''erlang xmerl''rabbitmq服务器''失败:E:无法纠正问题,您持有损坏的包。\n“,”rc“:100,“stderr”:“E:无法纠正问题,您持有损坏的包。\n”,“stderr_行”:[“E:无法纠正问题,您持有损坏的包。”],“stdout”:正在读取程序包列表…\n正在生成依赖关系树…\n正在读取状态信息…\n某些程序包无法安装。这可能意味着您\n请求了一种不可能的情况,或者如果您使用的是不稳定的分布,则说明某些所需的程序包尚未创建\n或已从传入程序中移出。\n以下信息可能不正确帮助解决此问题:\n\n以下包具有未满足的依赖项:\n erlang ftp:Dependes:erlang base(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但要安装1:20.2.2+dfsg-1ubuntu2或\n erlang base hipe(=1:22.0.7+dfsg-1build1~ubuntu18.04.1)但它不会被安装\n取决于:erlang运行时工具(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但要安装1:20.2.2+dfsg-1ubuntu2\n取决于:erlang ssl(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但要安装1:20.2.2+dfsg-1ubuntu2\n erlang tftp:Dependes:erlang基(=1:22.0.7+dfsg-1build1~ubuntu18.04.1)但要安装1:20.2.2+dfsg-1ubuntu2或\n erlang基本hipe(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但不会安装它“,”标准输出行“:[“读取程序包列表…”,“构建依赖关系树…”,“读取状态信息…””无法安装某些程序包。这可能意味着您已“,”请求了一种不可能的情况,或者如果您正在使用“不稳定的”分发版“,”某些必需的程序包尚未创建“,”或已从传入程序中移出。”,“以下信息可能有助于解决此情况:,”以下包具有未满足的依赖项:“,”erlang ftp:Dependes:erlang base(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但要安装1:20.2.2+dfsg-1ubuntu2或“,”erlang base hipe(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但不会安装它“,”Dependes:erlang运行时工具(=1:22.0.7+dfsg-1build1~ubuntu18.04.1)但要安装1:20.2.2+dfsg-1ubuntu2”,“依赖项:erlang ssl(=1:22.0.7+dfsg-1build1~ubuntu18.04.1)但要安装1:20.2.2+dfsg-1ubuntu2”,“erlang tftp:依赖项:erlang基础(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但要安装1:20.2.2+dfsg-1ubuntu2”erlang基本hipe(=1:22.0.7+dfsg-1build1~ubuntu18.04.1),但不会安装“]}
无法了解如何解决此问题。我正在以Hyper-V来宾身份运行Ubuntu。是否需要将“elang”部分与apt部分分开,然后尝试使用apt get运行

我的操作系统版本-Ubuntu 18.04.3 LTS


更新:

在几次谷歌搜索之后,我发现我试图用错误的方式为Ubuntu 18.04.3 LTS安装RabbitMQ服务器和erlang。因此我修改了我的Ansible Playbook,如下所示。在这里发布更新的Playbook代码,以备将来有人需要

---
- 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
感谢您的帮助和指导。将状态标记为已解决

失败:E:无法纠正问题,您持有的软件包已损坏。\n,“rc”:100

A:您似乎已标记为保留损坏的包裹。请列出“保留”的包裹

shell>sudo apt mark showhold
并取消对损坏的包的设置保留。如果您保留了任何“保留”包,请确保您知道自己在做什么

shell>sudo apt mark unhold{package}
现在,请手动尝试playbook中的shell命令来修复、解析、更新和升级。当打包再次从命令行运行时,请尝试Ansible



可以通过Ansible模块选项来管理选择:
安装、保持、卸载、清除

这与Ansible无关,我很确定手动执行所有这些步骤会遇到同样的问题。您能确认吗?建议:如果您将
变为:true
,则无需将sudo用于任务,并且您不应将
shell
用于apt相关操作这是依赖项解决问题,Ansible也无能为力。例如:
erlang ftp:Dependes:erlang base(=1:22.0.7+dfsg-1build1~ubuntu18.04.1)
但是要安装
1:20.2.2+dfsg-1ubuntu2
。请尝试指定可以满足依赖关系的软件包版本。如
name:package name=1.0.0
@Baptistemile Mathias.。你是对的。手动运行时,我遇到了相同的错误。有任何帮助吗?@SeshadriC尝试了apt get install erlang-base1:22.0.7和apt get install-y-f erlang base=1:22.0.7+dfsg-1build1..均显示错误-“未找到“erlang base”的版本“1:22.0.7+dfsg-1build1”。我是Ubuntu新手。可用版本似乎是
1:20.2.2+dfsg-1ubuntu2
,您可以尝试此版本以及@VladimirBotka建议的内容。谢谢。我已通过其他方式解决了此问题。使用解决方案更新了问题。