prudentia path weirdness:找不到使用相对于当前目录的路径的框

时间:2014-06-25 19:36:06

标签: python ansible prudentia

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

这是我的目录树:

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)解决我的情况(失败的Prudentia)和2)防止它再次发生。

3 个答案:

答案 0 :(得分:2)

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

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

而不是:

$prudentia_dir/tasks/common-setup.yml

可能您正在使用以前版本的盒式文件,并使用较新的prudentia版本。

答案 1 :(得分:2)

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

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

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

答案 2 :(得分: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

之后,一切都应该是好的。