【问题标题】:Ansible and Playbook. How to convert shell commands into yaml syntax?Ansible 和剧本。如何将 shell 命令转换为 yaml 语法?
【发布时间】:2014-01-27 02:56:27
【问题描述】:

我是 Ansible 的新手,我不明白所有人如何轻松地用 Ansible/YAML 语法编写 shell 命令。可能是我错过了文档中解释清楚的页面。

例如:如果我想在我的远程机器上执行这些命令,我​​需要在我的playbook.yml 中写什么:

sudo apt-get install software-properties-common
sudo apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mariadb.biz.net.id//repo/5.5/ubuntu precise main'

我想应该是这样的:

- name: install mariadb
  apt: ...
  sudo: yes

【问题讨论】:

    标签: ubuntu syntax yaml vagrant ansible


    【解决方案1】:

    作为原始 shell 命令modules 将完成 bash 脚本的简单翻译。它们很少会成为幂等动作。它们不能运行两次而不产生错误。

    这样做的 Ansible 方法是在您的情况下使用适当的模块

    mariadb 的示例

    【讨论】:

      【解决方案2】:

      答案是Ansible Modules!)这其实是我需要的。 快速搜索后,我认为我的命令将类似于:

      -raw: sudo apt-get install software-properties-common
      -raw: apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
       etc..
      

      【讨论】:

      • 这将导致您每次在该服务器上运行 playbook 时都运行命令,从而导致未来运行时可能出现错误或失败。除非模块不可用,否则永远不要使用它。
      猜你喜欢
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多