对于我们的每个服务器(web和perls),我们为每种类型的服务器提供不同的挂载点。所以对于Web服务器,我想使用" web_mounts"的条目。和perls将是" perl_mounts。"
如果我硬编码" web_mounts"进入" with_items,"它工作正常。否则,它告诉我" nfs_group"未定义。
import React from 'react';
import CheckpointView from './CheckpointView';
class OneCheckpointData extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
checkpoint: null,
user: null
};
}
componentWillMount() {
this.loadCheckpoint();
this.context.getUser((data) => this.setState({ user: data }));
}
loadCheckpoint() {
$.ajax({
url: `/api/v1/modules/three/cp/${this.props.params.cp_id}`,
method: 'GET',
}).done((data) => {
this.setState({ checkpoint: data });
});
}
render() {
return this.state.checkpoint ? <CheckpointView user={this.state.user} checkpoint={this.state.checkpoint} /> : null;
}
}
OneCheckpointData.displayName = OneCheckpointData;
OneCheckpointData.contextTypes = {
getUser: React.PropTypes.func.isRequired
};
export default OneCheckpointData;
roles:
- { role: webs, nfs_group: "web_mounts" }
---
web_mounts:
- { source: "nfs.local:/nfs/web1, dest: "/web1", opts: "rw,noatime" }
- { source: "nfs.local:/nfs/web2, dest: "/web2", opts: "rw,noatime" }
perl_mounts:
- { source: "nfs.local:/nfs/perl1, dest: "/perl1", opts: "rw,noatime" }
- { source: "nfs.local:/nfs/perl2, dest: "/perl2", opts: "rw,noatime" }
答案 0 :(得分:1)
将你的坐骑分组在这样的字典中:
---
mounts:
web_mounts:
- { source: "nfs.local:/nfs/web1", dest: "/web1", opts: "rw,noatime" }
- { source: "nfs.local:/nfs/web2", dest: "/web2", opts: "rw,noatime" }
perl_mounts:
- { source: "nfs.local:/nfs/perl1", dest: "/perl1", opts: "rw,noatime" }
- { source: "nfs.local:/nfs/perl2", dest: "/perl2", opts: "rw,noatime" }
并访问这样的dict元素:
- name: Create fstab entries
mount: fstab=nfs state=present opts="{{ item.opts }}" src="{{ item.source }}" name="{{ item.dest }}"
with_items: "{{ mounts[nfs_group] }}"
至于&#34; nfs_group未定义&#34; 错误,请检查您是否正确调用了角色 - 您的角色名称是&#34; nfs_mounts&#34;你的顶级剧本适用于角色&#34;网站&#34;。