2

Prudentia 找不到我定义的框。我很确定盒子在那里。当我使用绝对路径时,它会抱怨$prudentia_dir在 Ansible 中。

这是我的目录树:

deployment/
|-- Readme.md
|-- boxes
|   |-- common_vars.yml
|   |-- dev.yml
|   |-- dev_vars.yml
|   |-- enable_cd.yml
|   |-- staging.yml
|   `-- staging_vars.yml
`-- components
    |-- api.yml
    |-- base.yml
    |-- client.yml
    |-- files
    |   `-- ssh
    |       |-- id_rsa
    |       `-- id_rsa.pub
    |-- mongo.yml
    `-- templates
        |-- api
        |   |-- logback.xml.j2
        |   `-- upstart.conf.j2
        `-- client
            `-- nginx.conf.j2

当我启动 Prudentia SSH 并尝试注册一个盒子时:

(Prudentia > Ssh) register
Specify the playbook path: deployment/boxes/staging.yml
25-06-2014 18:48:35.339 [root] ERROR: Box not added.
Traceback (most recent call last):
  File "/Users/rob/tmp/prudentia/src/ssh.py", line 26, in register
    hostname = self.fetch_box_hostname(playbook)
  File "/Users/rob/tmp/prudentia/src/simple.py", line 202, in fetch_box_hostname
    with open(playbook, 'r') as f:
IOError: [Errno 2] No such file or directory: 'deployment/boxes/staging.yml'

There was some problem while adding the box: [Errno 2] No such file or directory: 'boxes/staging.yml'

在对相对路径应该是什么不同的假设进行了几次尝试之后,我决定使用绝对路径。在该尝试中发生以下错误:

(Prudentia > Ssh) register
Specify the playbook path: /Users/rob/......./deployment/boxes/staging.yml
Specify the box name [default: acme-staging]:
Specify the address of the instance: poc01
Specify the remote user [default: rob]: pocuser
Specify the password for the remote user [default: ssh key]:
25-06-2014 18:50:07.654 [root] ERROR: Box not added.
Traceback (most recent call last):
  File "/Users/rob/tmp/prudentia/src/ssh.py", line 33, in register
    self.add_box(box)
  File "/Users/rob/tmp/prudentia/src/simple.py", line 164, in add_box
    self.load_tags(box)
  File "/Users/rob/tmp/prudentia/src/simple.py", line 180, in load_tags
    play = Play(playbook, playbook.playbook[0], dirname(b.playbook))
  File "/Users/rob/tmp/prudentia/p-env/lib/python2.7/site-packages/ansible/playbook/play.py", line 152, in __init__
    self._tasks      = self._load_tasks(self._ds.get('tasks', []), load_vars)
  File "/Users/rob/tmp/prudentia/p-env/lib/python2.7/site-packages/ansible/playbook/play.py", line 588, in _load_tasks
    loaded = self._load_tasks(data, mv, default_vars, included_sudo_vars, list(included_additional_conditions), original_file=include_filename, role_name=new_role)
  File "/Users/rob/tmp/prudentia/p-env/lib/python2.7/site-packages/ansible/playbook/play.py", line 583, in _load_tasks
    data = utils.parse_yaml_from_file(include_filename, vault_password=self.vault_password)
  File "/Users/rob/tmp/prudentia/p-env/lib/python2.7/site-packages/ansible/utils/__init__.py", line 551, in parse_yaml_from_file
    raise errors.AnsibleError("file could not read: %s" % path)
AnsibleError: file could not read: /Users/rob/dev/...../components/$prudentia_dir/tasks/mongodb.yml

There was some problem while adding the box: file could not read: /Users/rob/...../deployment/components/$prudentia_dir/tasks/mongodb.yml

之后,Prudentia 退出并在每次尝试重新启动时都失败并出现相同的错误。

Prudentia 中似乎有一些关于它想如何使用的假设,我不明白。请帮助 1)解决我的情况(保诚失败)和 2)防止它再次发生。

4

3 回答 3

2

看看你的内部staging.yml。应该以这种格式指定路径:

"{{prudentia_dir}}/tasks/common-setup.yml"

而不是:

$prudentia_dir/tasks/common-setup.yml

可能您正在使用具有较新 prudentia 版本的先前版本的 box 文件。

于 2014-06-25T21:18:24.163 回答
2

使用 playbook 的绝对路径绝对是注册新盒子时使用的正确方法,我们将在下一个版本中更明确地解决这个问题。

关于另一个问题@DmitryEvsee 是对的,问题是由于更新了 Ansible 1.6 的一部分。

有关更多信息http://docs.ansible.com/playbooks_variables.html#using-variables-about-jinja2

于 2014-06-25T21:26:46.767 回答
0

我有一个类似的问题:

File "/Users/iwein/projects/prudentia/p-env/lib/python2.7/site-packages/ansible/utils/__init__.py", line 551, in parse_yaml_from_file
raise errors.AnsibleError("file could not read: %s" % path)

ansible.errors.AnsibleError:文件无法读取:/Users/iwein/projects/.../deployment/boxes/$prudentia_dir/tasks/common-setup.yml

我编辑~/projects/prudentia/env/ssh/.boxes.json(那是我的 prudentia 结帐所在的位置)并删除了所有内容。然后普鲁登蒂亚高兴地跑了。

接下来我注册了 ... 框,但它又在抱怨:

There was some problem while adding the box: file could not read: /Users/iwein/projects/…/deployment/boxes/$prudentia_dir/tasks/common-setup.yml

然后我修改了框定义 yml 文件以使用"{{prudentia_dir}}/whatever"而不是$prudentia_dir. 我还必须修改我使用的一些组件。我使用了这个替换模式::%s/\$([^/]*)(.*)/"{{$1}}$2"/g

在那之后,一切都应该是桃色的。

于 2014-06-26T06:20:14.040 回答