我正在使用Ansible在ec2上构建一台机器。 但我也有流浪汉在本地测试脚本。
这是我的剧本
- name: Provision ec2 hosts: all user: vagrant sudo: yes gather_facts: true vars: gsutil_user_home: "vagrant"如果我想将此剧本用于EC2,我必须将user和gsutil_user_home更改为ubuntu以使其正常工作。 无论如何,我可以将其作为一个变量,并根据一些参数告诉Ansible它需要运行哪个用户?
I'm building a machine on ec2 using Ansible. But I also have vagrant to test the script locally.
Here's my playbook
- name: Provision ec2 hosts: all user: vagrant sudo: yes gather_facts: true vars: gsutil_user_home: "vagrant"If I want to use this playbook for EC2 I have to change the user and gsutil_user_home to be ubuntu to get it to work. Is there anyway I can make that as a variable and tell Ansible which user it needs to run based on some argument?
最满意答案
如果这些值通常与您的剧本持续时间保持一致,您通常会将它们设置为库存中的组/主机变量,并为不同的环境设置不同的库存或组。 但是如果你真的想用vars做它并用-e传递它们,那也没关系:
- name: Provision ec2 hosts: all user: {{ my_ec2_user }} sudo: yes gather_facts: true vars: gsutil_user_home: {{ gsutil_user_home }}If these values are generally consistent for the duration of your playbooks, you'd usually set them as group/host vars in inventory, and have different inventories or groups for different environments. But if you really want to do it with vars and pass them in with -e, that's fine too:
- name: Provision ec2 hosts: all user: {{ my_ec2_user }} sudo: yes gather_facts: true vars: gsutil_user_home: {{ gsutil_user_home }}更多推荐
发布评论