需要这个基本的 ansible 变量解释
Need this basic ansible variables explaination
我知道这是一个非常基本的问题,但我真的很想得到解释:
repos:
- name: 'EPEL'
url: 'http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'
key: 'http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6'
- name: 'RPMForge'
url: 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'
key: 'http://apt.sw.be/RPM-GPG-KEY.dag.txt'
- name: 'Remi'
url: 'http://rpms.famillecollet.com/enterprise/remi-release-6.rpm'
key: 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi'
- name: 'Webtatic'
url: 'http://mirror.webtatic.com/yum/el6/latest.rpm'
key: 'http://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy'
比如什么是"repo",我觉得是榜单吧?但是 "name"、"url" 和 "key" 是什么?为什么只有 "name" 前面有“-”?
提前致谢
如果您从 python
dict
和 list
:
的角度来看,也许它会有所帮助
$ python -c "
import yaml
import pprint
pp = pprint.PrettyPrinter(indent=3);
x = yaml.load('''repos:
- name: 'EPEL'
url: 'http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'
key: 'http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6'
- name: 'RPMForge'
url: 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'
key: 'http://apt.sw.be/RPM-GPG-KEY.dag.txt'
- name: 'Remi'
url: 'http://rpms.famillecollet.com/enterprise/remi-release-6.rpm'
key: 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi'
- name: 'Webtatic'
url: 'http://mirror.webtatic.com/yum/el6/latest.rpm'
key: 'http://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy'
''');
pp.pprint( x );"
{ 'repos': [ { 'key': 'http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6',
'name': 'EPEL',
'url': 'http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'},
{ 'key': 'http://apt.sw.be/RPM-GPG-KEY.dag.txt',
'name': 'RPMForge',
'url': 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'},
{ 'key': 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi',
'name': 'Remi',
'url': 'http://rpms.famillecollet.com/enterprise/remi-release-6.rpm'},
{ 'key': 'http://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy',
'name': 'Webtatic',
'url': 'http://mirror.webtatic.com/yum/el6/latest.rpm'}]}
$
所以:
repos
是 dict
中的一个元素(键)
- 键
repos
的值是 list
的 dicts
why only "name" has the "-" infront of it?
问题无效。这就是 YAML 语法,当你想声明一个 dict
时,你就是这样做的。
O 正如 Marc 所说:ansible YAML Syntax
我知道这是一个非常基本的问题,但我真的很想得到解释:
repos:
- name: 'EPEL'
url: 'http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'
key: 'http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6'
- name: 'RPMForge'
url: 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'
key: 'http://apt.sw.be/RPM-GPG-KEY.dag.txt'
- name: 'Remi'
url: 'http://rpms.famillecollet.com/enterprise/remi-release-6.rpm'
key: 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi'
- name: 'Webtatic'
url: 'http://mirror.webtatic.com/yum/el6/latest.rpm'
key: 'http://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy'
比如什么是"repo",我觉得是榜单吧?但是 "name"、"url" 和 "key" 是什么?为什么只有 "name" 前面有“-”?
提前致谢
如果您从 python
dict
和 list
:
$ python -c "
import yaml
import pprint
pp = pprint.PrettyPrinter(indent=3);
x = yaml.load('''repos:
- name: 'EPEL'
url: 'http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'
key: 'http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6'
- name: 'RPMForge'
url: 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'
key: 'http://apt.sw.be/RPM-GPG-KEY.dag.txt'
- name: 'Remi'
url: 'http://rpms.famillecollet.com/enterprise/remi-release-6.rpm'
key: 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi'
- name: 'Webtatic'
url: 'http://mirror.webtatic.com/yum/el6/latest.rpm'
key: 'http://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy'
''');
pp.pprint( x );"
{ 'repos': [ { 'key': 'http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6',
'name': 'EPEL',
'url': 'http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'},
{ 'key': 'http://apt.sw.be/RPM-GPG-KEY.dag.txt',
'name': 'RPMForge',
'url': 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'},
{ 'key': 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi',
'name': 'Remi',
'url': 'http://rpms.famillecollet.com/enterprise/remi-release-6.rpm'},
{ 'key': 'http://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy',
'name': 'Webtatic',
'url': 'http://mirror.webtatic.com/yum/el6/latest.rpm'}]}
$
所以:
repos
是dict
中的一个元素(键)
- 键
repos
的值是list
的dicts
why only "name" has the "-" infront of it?
问题无效。这就是 YAML 语法,当你想声明一个 dict
时,你就是这样做的。
O 正如 Marc 所说:ansible YAML Syntax