Ansible 和 Playbook.如何将 shell 命令转换为 yaml 语法? [英] Ansible and Playbook. How to convert shell commands into yaml syntax?

查看:51
本文介绍了Ansible 和 Playbook.如何将 shell 命令转换为 yaml 语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm a newbie in Ansible and I don't understand how all people easily write shell commands in the Ansible/YAML syntax. May be I've missed a page from the documentation where it is explained well.

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

For example: What do I need to write in my playbook.yml if I want to perform these commands in my remote machines:

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

推荐答案

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

As raw shell command modules will do the trick for plain translation of bash scripts. They will rarely end up to be idempotent actions. They can not be run twice without producing errors.

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

The Ansible way of doing this is to use the appropriate modules, in your case

  • apt_key : add the gpg key
  • apt_repository : install the repository
  • apt : install the package

mariadb

这篇关于Ansible 和 Playbook.如何将 shell 命令转换为 yaml 语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆