What is the Ansible policy for defining variables and constants in the vars, defaults or tasks directory? ...
WOW air has ceased operation, can I get my tickets refunded?
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
How to write papers efficiently when English isn't my first language?
If the heap is initialized for security, then why is the stack uninitialized?
Why were Madagascar and New Zealand discovered so late?
Anatomically Correct Mesopelagic Aves
Increase performance creating Mandelbrot set in python
What do "high sea" and "carry" mean in this sentence?
Robert Sheckley short story about vacation spots being overwhelmed
When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?
Customer Requests (Sometimes) Drive Me Bonkers!
Natural language into sentence logic
How to write the block matrix in LaTex?
Return the Closest Prime Number
Is HostGator storing my password in plaintext?
Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?
How to safely derail a train during transit?
How can I quit an app using Terminal?
How to make a variable always equal to the result of some calculations?
Why didn't Khan get resurrected in the Genesis Explosion?
Inappropriate reference requests from Journal reviewers
Need some help with wall behind rangetop
Why does standard notation not preserve intervals (visually)
Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?
What is the Ansible policy for defining variables and constants in the vars, defaults or tasks directory?
The Next CEO of Stack Overflowlocal ansible-playbook run playbook with vars for roleAnsible and fact dependent variablesWhat is the correct syntax of defining role dependencies in the meta/main.yml in Ansible?What is reasonable performance for a simple Ansible playbook against ~100 hosts?Ansible variables and text replacementAnsible: list all variables required for a playbookAnsible: access variables and dump to CSV fileissues with Ansible and vars precedence with dependenciesAnsible: run additional tasks for specific inventoryAnsible Playbook and syntax issue with variables
I have read multiple documents including this one and checked multiple ansible roles on GitHub, but it is unclear to me when to define a variable and when one is defined where to put it, i.e. in the defaults
, tasks
or vars
directory.
I would like to receive guidelines so that I do not have to spend a lot of time about thinking whether a variable is required and if that is the case where to put it.
defaults
sensu_host: localhost
sensu_home: /etc/sensu
sensu_conf_d: "{{ sensu_home }}/conf.d"
tasks
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
- build-essential
- ntp
or should the items be defined in a variable:
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
{{ packages }}
vars
__sensu_repo_url: deb http://sensu.global.ssl.fastly.net/apt sensu main
__sensu_repo_key_url: http://sensu.global.ssl.fastly.net/apt/pubkey.gp
Is there a certain checklist, e.g.
If a, b, c then the variable needs to be declared in defaults
if d, e, f then the v
if g, h, i then define it in tasks
╔═══════════╦═════════════════╗
║ directory ║ characteristics ║
╠═══════════╬═════════════════╣
║ defaults ║ constants, e.g. ║
║ tasks ║ bla, e.g. ║
║ vars ║ variables ║
╚═══════════╩═════════════════╝
ansible ansible-playbook
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have read multiple documents including this one and checked multiple ansible roles on GitHub, but it is unclear to me when to define a variable and when one is defined where to put it, i.e. in the defaults
, tasks
or vars
directory.
I would like to receive guidelines so that I do not have to spend a lot of time about thinking whether a variable is required and if that is the case where to put it.
defaults
sensu_host: localhost
sensu_home: /etc/sensu
sensu_conf_d: "{{ sensu_home }}/conf.d"
tasks
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
- build-essential
- ntp
or should the items be defined in a variable:
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
{{ packages }}
vars
__sensu_repo_url: deb http://sensu.global.ssl.fastly.net/apt sensu main
__sensu_repo_key_url: http://sensu.global.ssl.fastly.net/apt/pubkey.gp
Is there a certain checklist, e.g.
If a, b, c then the variable needs to be declared in defaults
if d, e, f then the v
if g, h, i then define it in tasks
╔═══════════╦═════════════════╗
║ directory ║ characteristics ║
╠═══════════╬═════════════════╣
║ defaults ║ constants, e.g. ║
║ tasks ║ bla, e.g. ║
║ vars ║ variables ║
╚═══════════╩═════════════════╝
ansible ansible-playbook
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
@techraf Question has been updated. It is an example of putting the packages in the tasks instead of defining it as a variable
– 030
Aug 21 '16 at 12:56
I think you are mixing two things. You can define a variable in a task usingset_fact
. Now, to an already too-broad-question "where should the variables be defined?" you added "should I use variables at all?" Ansible is a collaborative, open, elastic project; the fact that 16 places for defining variables evolved over time is because of the needs of different users and different approaches. There's no "one and only way", depending on the problem you want to solve you use different tools.
– techraf
Aug 21 '16 at 13:05
add a comment |
I have read multiple documents including this one and checked multiple ansible roles on GitHub, but it is unclear to me when to define a variable and when one is defined where to put it, i.e. in the defaults
, tasks
or vars
directory.
I would like to receive guidelines so that I do not have to spend a lot of time about thinking whether a variable is required and if that is the case where to put it.
defaults
sensu_host: localhost
sensu_home: /etc/sensu
sensu_conf_d: "{{ sensu_home }}/conf.d"
tasks
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
- build-essential
- ntp
or should the items be defined in a variable:
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
{{ packages }}
vars
__sensu_repo_url: deb http://sensu.global.ssl.fastly.net/apt sensu main
__sensu_repo_key_url: http://sensu.global.ssl.fastly.net/apt/pubkey.gp
Is there a certain checklist, e.g.
If a, b, c then the variable needs to be declared in defaults
if d, e, f then the v
if g, h, i then define it in tasks
╔═══════════╦═════════════════╗
║ directory ║ characteristics ║
╠═══════════╬═════════════════╣
║ defaults ║ constants, e.g. ║
║ tasks ║ bla, e.g. ║
║ vars ║ variables ║
╚═══════════╩═════════════════╝
ansible ansible-playbook
I have read multiple documents including this one and checked multiple ansible roles on GitHub, but it is unclear to me when to define a variable and when one is defined where to put it, i.e. in the defaults
, tasks
or vars
directory.
I would like to receive guidelines so that I do not have to spend a lot of time about thinking whether a variable is required and if that is the case where to put it.
defaults
sensu_host: localhost
sensu_home: /etc/sensu
sensu_conf_d: "{{ sensu_home }}/conf.d"
tasks
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
- build-essential
- ntp
or should the items be defined in a variable:
- name: be sure {{ item }} is installed
apt:
name: "{{ item }}"
state: latest
with_items:
{{ packages }}
vars
__sensu_repo_url: deb http://sensu.global.ssl.fastly.net/apt sensu main
__sensu_repo_key_url: http://sensu.global.ssl.fastly.net/apt/pubkey.gp
Is there a certain checklist, e.g.
If a, b, c then the variable needs to be declared in defaults
if d, e, f then the v
if g, h, i then define it in tasks
╔═══════════╦═════════════════╗
║ directory ║ characteristics ║
╠═══════════╬═════════════════╣
║ defaults ║ constants, e.g. ║
║ tasks ║ bla, e.g. ║
║ vars ║ variables ║
╚═══════════╩═════════════════╝
ansible ansible-playbook
ansible ansible-playbook
edited Aug 21 '16 at 12:55
030
asked Aug 21 '16 at 10:57
030030
3,79964087
3,79964087
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
@techraf Question has been updated. It is an example of putting the packages in the tasks instead of defining it as a variable
– 030
Aug 21 '16 at 12:56
I think you are mixing two things. You can define a variable in a task usingset_fact
. Now, to an already too-broad-question "where should the variables be defined?" you added "should I use variables at all?" Ansible is a collaborative, open, elastic project; the fact that 16 places for defining variables evolved over time is because of the needs of different users and different approaches. There's no "one and only way", depending on the problem you want to solve you use different tools.
– techraf
Aug 21 '16 at 13:05
add a comment |
@techraf Question has been updated. It is an example of putting the packages in the tasks instead of defining it as a variable
– 030
Aug 21 '16 at 12:56
I think you are mixing two things. You can define a variable in a task usingset_fact
. Now, to an already too-broad-question "where should the variables be defined?" you added "should I use variables at all?" Ansible is a collaborative, open, elastic project; the fact that 16 places for defining variables evolved over time is because of the needs of different users and different approaches. There's no "one and only way", depending on the problem you want to solve you use different tools.
– techraf
Aug 21 '16 at 13:05
@techraf Question has been updated. It is an example of putting the packages in the tasks instead of defining it as a variable
– 030
Aug 21 '16 at 12:56
@techraf Question has been updated. It is an example of putting the packages in the tasks instead of defining it as a variable
– 030
Aug 21 '16 at 12:56
I think you are mixing two things. You can define a variable in a task using
set_fact
. Now, to an already too-broad-question "where should the variables be defined?" you added "should I use variables at all?" Ansible is a collaborative, open, elastic project; the fact that 16 places for defining variables evolved over time is because of the needs of different users and different approaches. There's no "one and only way", depending on the problem you want to solve you use different tools.– techraf
Aug 21 '16 at 13:05
I think you are mixing two things. You can define a variable in a task using
set_fact
. Now, to an already too-broad-question "where should the variables be defined?" you added "should I use variables at all?" Ansible is a collaborative, open, elastic project; the fact that 16 places for defining variables evolved over time is because of the needs of different users and different approaches. There's no "one and only way", depending on the problem you want to solve you use different tools.– techraf
Aug 21 '16 at 13:05
add a comment |
1 Answer
1
active
oldest
votes
There are no policies for defining variables and constants in the vars and defaults directory.
Variables in the role/defaults
directory have the lowest priority. So it makes sense to put all the variables defined in the role in role/defaults/main.yml
for reference. If a variable default value depends on the distribution I put it under vars/{{ ansible_os_family }}.yml
and include it like this:
# Variable setup.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
I also put variables which are kind of constant like urls under vars
as well.
But again there are no real policies. It is up to you how to do things. I personally orientate my role structure and playbook style by geerlingguy.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f798164%2fwhat-is-the-ansible-policy-for-defining-variables-and-constants-in-the-vars-def%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are no policies for defining variables and constants in the vars and defaults directory.
Variables in the role/defaults
directory have the lowest priority. So it makes sense to put all the variables defined in the role in role/defaults/main.yml
for reference. If a variable default value depends on the distribution I put it under vars/{{ ansible_os_family }}.yml
and include it like this:
# Variable setup.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
I also put variables which are kind of constant like urls under vars
as well.
But again there are no real policies. It is up to you how to do things. I personally orientate my role structure and playbook style by geerlingguy.
add a comment |
There are no policies for defining variables and constants in the vars and defaults directory.
Variables in the role/defaults
directory have the lowest priority. So it makes sense to put all the variables defined in the role in role/defaults/main.yml
for reference. If a variable default value depends on the distribution I put it under vars/{{ ansible_os_family }}.yml
and include it like this:
# Variable setup.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
I also put variables which are kind of constant like urls under vars
as well.
But again there are no real policies. It is up to you how to do things. I personally orientate my role structure and playbook style by geerlingguy.
add a comment |
There are no policies for defining variables and constants in the vars and defaults directory.
Variables in the role/defaults
directory have the lowest priority. So it makes sense to put all the variables defined in the role in role/defaults/main.yml
for reference. If a variable default value depends on the distribution I put it under vars/{{ ansible_os_family }}.yml
and include it like this:
# Variable setup.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
I also put variables which are kind of constant like urls under vars
as well.
But again there are no real policies. It is up to you how to do things. I personally orientate my role structure and playbook style by geerlingguy.
There are no policies for defining variables and constants in the vars and defaults directory.
Variables in the role/defaults
directory have the lowest priority. So it makes sense to put all the variables defined in the role in role/defaults/main.yml
for reference. If a variable default value depends on the distribution I put it under vars/{{ ansible_os_family }}.yml
and include it like this:
# Variable setup.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
I also put variables which are kind of constant like urls under vars
as well.
But again there are no real policies. It is up to you how to do things. I personally orientate my role structure and playbook style by geerlingguy.
answered Aug 22 '16 at 13:50
Henrik PingelHenrik Pingel
4,52521430
4,52521430
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f798164%2fwhat-is-the-ansible-policy-for-defining-variables-and-constants-in-the-vars-def%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@techraf Question has been updated. It is an example of putting the packages in the tasks instead of defining it as a variable
– 030
Aug 21 '16 at 12:56
I think you are mixing two things. You can define a variable in a task using
set_fact
. Now, to an already too-broad-question "where should the variables be defined?" you added "should I use variables at all?" Ansible is a collaborative, open, elastic project; the fact that 16 places for defining variables evolved over time is because of the needs of different users and different approaches. There's no "one and only way", depending on the problem you want to solve you use different tools.– techraf
Aug 21 '16 at 13:05