Questions tagged «ansible-2.x»

7
Ansible-如果未定义变量,请使用默认值
我正在自定义users角色中的linux 创建。我需要让我的角色定制的用户home_directory,group_name,name,password。 我想知道是否有更灵活的方式来应对默认值。 我知道以下代码是可能的: - name: Create default user: name: "default_name" when: my_variable is not defined - name: Create custom user: name: "{{my_variable}}" when: my_variable is defined 但是正如我提到的,有很多可选变量,这创造了很多可能性。 是否有类似上面的代码? user: name: "default_name", "{{my_variable}}" 该代码应name="default_name"在my_variable未定义时设置。 我可以设置所有变量defaults/main.yml并像这样创建用户: - name: Create user user: name: "{{my_variable}}" 但是这些变量在一个非常大的散列中,并且该散列中有一些哈希不能为默认值。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.