gpt4 book ai didi

ansible - 将 yml 内 shell 的响应用于 Ansible playbook

转载 作者:行者123 更新时间:2023-12-02 12:15:32 25 4
gpt4 key购买 nike

我想通过 Ansible playbook 安装 MongoDB,我按照以下说明进行操作: https://www.howtoforge.com/tutorial/install-mongodb-on-ubuntu-16.04/

关于“第2步 - 创建源列表文件 MongoDB”的步骤

我应该使用:

echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

使用以下命令获取 ubuntu 版本:

$(lsb_release -sc)

我如何通过 yml 文件来完成并通过 ansible palybook 运行它?我使用了下面的 yml 命令,但它不起作用并给出错误,因为我在脚本中使用 shell 命令“$(lsb_release -sc)”

- name: Create source list file MongoDB
sudo: yes
lineinfile: >
line="deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse"
dest=/etc/apt/sources.list.d/mongodb-org-3.2.list
state=present
create=yes

最佳答案

apt_repository Ansible 中的模块:

- apt_repository:
repo: deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release | lower }}/mongodb-org/3.2 multiverse
state: present

关于ansible - 将 yml 内 shell 的响应用于 Ansible playbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46914343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com