不推荐使用角色包含中的参数remote_user,解决方法是什么?

时间:2017-05-29 07:56:58

标签: ansible ansible-2.x ansible-role

我正在使用Ansible来实现系统的自动化。

我有一个取决于两个角色的Ansible剧本。 第一个角色在远程服务器上创建用户(“specific_user”)。 第二个角色使用这个用户做一堆东西。

我的第一个解决方案是以下(我的剧本):

---
- hosts: all

roles:
  - { role: ansible-role1, remote_user: root }
  - { role: ansible-role2, remote_user: specific_user }
...

但是,我在运行它时会收到来自Ansible的以下警告:

Using 'remote_user' as a role param has been deprecated.
In the future, these values should be entered in the `vars:` section for
roles, but for now we'll store it as both a param and an attribute..

有什么替代方案?

1 个答案:

答案 0 :(得分:3)

目前这只是一条警告信息(直到Ansible 2.7版)。

如消息所示,您需要将语法更改为(在下面的示例中使用YAML,因为它更具可读性):

roles:
  - role: ansible-role1
    vars:
      remote_user: root
  - role: ansible-role2
    vars:
      remote_user: specific_user

...

相关问题