关于使用Ansible更新软件包的问题

关于使用Ansible更新软件包的问题,ansible,Ansible,我的Ansible playbook包含我想用最新版本安装的软件包;然而,这并没有发生。我知道使用apt您将无法获得最新的更新,但Ansible中更新最新软件包的最佳方法是什么 setup.yml sys_packages: [ 'curl', 'vim', 'git', 'ufw', 'wget', 'aptitude', 'ca-certificates', 'software-properties-common', 'gnupg-agent', 'vagrant', 'ansible',

我的Ansible playbook包含我想用最新版本安装的软件包;然而,这并没有发生。我知道使用
apt
您将无法获得最新的更新,但Ansible中更新最新软件包的最佳方法是什么

setup.yml

sys_packages: [ 'curl', 'vim', 'git', 'ufw', 'wget', 'aptitude', 'ca-certificates', 'software-properties-common', 'gnupg-agent', 'vagrant', 'ansible', 'python3-pip', 'apt-transport-https', 'virtualenv', 'bash', 'nodejs', 'npm', 'ntp', 'ntpdate', 'htop' ]
playbook.yml

### Complete setup of packages for Debian/Ubuntu distros
- name: Update and install all required system packages
    apt:
      name: "{{ sys_packages }}"
      state: latest
      update_cache: yes
我想安装Ansible脚本的发行版在Ubuntu版本上

更新:2020年12月19日
我真傻。我一直在研究并发现,如果可以在Ansible中使用
curl
命令或创建自定义PPA存储库,那么您就可以获得所需的每个包的当前版本,因为使用
apt get
(例如,在18.04和20.04中使用
apt get virtualbox
将提供不同的版本)。一旦我能够完成我的目标,我将更新我的帖子。

我能够成功地用我想要的某些包的最新更新更新我的包,例如ansible、git和vagrant。下面是代码的外观:

###### PPA Repository Setup
###### Add a complete set of repositories into the source list to be updated to the latest version.
###### The only repositories that are up to date are git, ansible, and vagrant. The others will have to be
###### installed separately.
    - name: Add stable repositories from PPA to system
      apt_repository:
          repo: "{{ item }}"
      loop:
        - ppa:ansible/ansible                     # Latest Ansible repo
        - ppa:git-core/ppa                        # Latest git repo
        - ppa:tiagohillebrandt/vagrant            # Latest Vagrant repo (this is a personal ppa so this needs to be wary)
假设您想为不同的存储库(如Docker)添加GPG密钥,下面是一个示例:

###### Docker Setup
###### Setup Docker's GPG key and Docker's repository. It is recommended prior to installation to have
###### these apps installed: apt-transport-https, ca-certificates, curl, gnupg-agent, and software-properties-common.
    - name: Add Docker GPG apt key
      apt_key:
        url: https://download.docker.com/linux/ubuntu/gpg
        state: present

    - name: Add Docker Repository
      apt_repository:
          repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
          state: present

现在,名为deb[arch=amd64]的回购协议https://download.docker.com/linux/ubuntu $(lsb_release-cs)稳定的是我需要解决的问题。如果你的Ubuntu版本是18.04。你会替换
$(lsb_release-cs)
使用
仿生
。但是,
lsb_发行版
应该提供版本。感谢所有人的帮助,我希望这能帮助任何人

我能够成功地用我想要的某些包的最新更新更新我的包,例如ansible、git和vagrant。下面是代码的外观:

###### PPA Repository Setup
###### Add a complete set of repositories into the source list to be updated to the latest version.
###### The only repositories that are up to date are git, ansible, and vagrant. The others will have to be
###### installed separately.
    - name: Add stable repositories from PPA to system
      apt_repository:
          repo: "{{ item }}"
      loop:
        - ppa:ansible/ansible                     # Latest Ansible repo
        - ppa:git-core/ppa                        # Latest git repo
        - ppa:tiagohillebrandt/vagrant            # Latest Vagrant repo (this is a personal ppa so this needs to be wary)
假设您想为不同的存储库(如Docker)添加GPG密钥,下面是一个示例:

###### Docker Setup
###### Setup Docker's GPG key and Docker's repository. It is recommended prior to installation to have
###### these apps installed: apt-transport-https, ca-certificates, curl, gnupg-agent, and software-properties-common.
    - name: Add Docker GPG apt key
      apt_key:
        url: https://download.docker.com/linux/ubuntu/gpg
        state: present

    - name: Add Docker Repository
      apt_repository:
          repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
          state: present

现在,名为deb[arch=amd64]的回购协议https://download.docker.com/linux/ubuntu $(lsb_release-cs)稳定的是我需要解决的问题。如果你的Ubuntu版本是18.04。你会替换
$(lsb_release-cs)
bionic
。但是,
lsb_发行版
应该提供版本。感谢所有人的帮助,我希望这能帮助任何人

你在理论上应该做的工作——因为你正在将
状态
设置为
最新
,并且你也在更新缓存。你在运行它时有任何错误吗?H软件包比您预期的要旧多少?如果您在主机本身上通过
apt get
手动尝试,它是否在您的目标主机上工作?可能尝试将
update\u cache\u retries
设置为更高的值,例如10(默认值为5)看看这是否有帮助。@costaparas谢谢你的回复costa。我能够成功地处理每个包,没有错误。让我们以我测试的Ubuntu18.04为例。当我为Ubuntu18.04运行带有模块
apt
的Ansible脚本时,我收到的
git
是2.17.1,当它应该是2.29.2时,vagrant是2.0.2它应该是2.2.14。我将使用
apt get
手动查看是否会有差异,以及
update\u cache\u retries
。从理论上讲,您所拥有的应该是可行的——因为您正在将
状态设置为
latest
,并且您也在更新缓存。您在运行缓存时是否遇到任何错误?如何操作软件包是否比您预期的要旧?如果您在主机本身上通过
apt get
手动尝试,它是否在您的目标主机上工作?可能尝试将
update\u cache\u retries
设置为更高的值,例如10(默认值为5)看看这是否有帮助。@costaparas谢谢你的回复costa。我能够成功地处理每个包,没有错误。让我们以我测试的Ubuntu18.04为例。当我为Ubuntu18.04运行带有模块
apt
的Ansible脚本时,我收到的
git
是2.17.1,当它应该是2.29.2时,vagrant是2.0.2应该是2.2.14。我将使用
apt get
手动查看是否会有差异,以及
update\u cache\u retries