本文介绍了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命令模块可以完成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语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:54