已弃用参数remote_user in role include,解决方法是什么?
问题描述:
我使用Ansible来完成我系统的自动化。已弃用参数remote_user in role include,解决方法是什么?
我有一个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..
什么是另类?
答
目前这只是一个警告消息(直到Ansible版本2.7)。
由于该消息暗示,你需要改变语法(在下面的例子中使用YAML,因为它更具有可读性):
roles:
- role: ansible-role1
vars:
remote_user: root
- role: ansible-role2
vars:
remote_user: specific_user
...
谢谢,我没理解警告现在很清楚 – MMacphail
我现在收到以下警告:'使用保留名称remote_user'找到变量,并且有一些后续问题: 1)是您推荐的语法,相当于{remote_user:root}? 2)你可以用这个语法覆盖角色变量吗? – MMacphail
这显然是在Ansible的过渡阶段。你使用什么版本?当你问这个问题时你是否使用了不同的版本? – techraf