简体   繁体   English

如何通过 ansible 剧本添加存储库

[英]How to add repository by ansible playbook

I want to do below command by ansible playbook我想按照 ansible 剧本执行以下命令

add-apt-repository cloud-archive:rocky

after some search I find this solution经过一番搜索,我找到了这个解决方案

- name: Add repositories
  apt_repository: repo='cloud-archive:rocky' state=present

But it does not work.What is the correct way to do that command by ansible playbook?但它不起作用。通过 ansible 剧本执行该命令的正确方法是什么?

You can use Ansible's Shell module passing the -y switch to add-apt-repository您可以使用 Ansible 的Shell 模块将 -y 开关传递给 add-apt-repository

- name: Ensure to add repository
  shell: sudo add-apt-repository cloud-archive:rocky -y

For ubuntu this repository module can be used, this does work and you can proceed with rest of the installation对于 ubuntu 可以使用此存储库模块,这确实有效,您可以继续安装 rest

 - name: Add php repository
   apt_repository:
      repo: ppa:ondrej/php
      state: present

Ref: https://docs.ansible.com/ansible/2.9/modules/apt_repository_module.html参考: https://docs.ansible.com/ansible/2.9/modules/apt_repository_module.html

Shell can definately do it but when you start working on production environment having specific module for the job is advisable to avoid any security/best practices violations Shell 肯定可以做到,但是当您开始在具有特定工作模块的生产环境中工作时,建议避免违反任何安全/最佳实践

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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