Ansible - is it possible to add tags to hosts inside inventory?
As the topic says, my question is if its possible to add tags to the hosts described inside the inventory?
My goal is to be able to run the ansible-playbook on specific host/group of hosts which has that specific tag e.g only on servers with tag 'Env=test and Type=test'
So for example when I run the playbook:
ansible-playbook -i hosts test.yml --extra-vars "Env=${test} Type=${test}"
I will pass the tags in the command and it will run only on the filtered hosts.
Thanks a lot!
Update:
Alternatively maybe doing something like in dynamic inventory? https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html#developing-inventory
[tag_Name_staging_foo]
[tag_Name_staging_bar]
[staging:children]
tag_Name_staging_foo
tag_Name_staging_bar
ansible ansible-2.x ansible-inventory
add a comment |
As the topic says, my question is if its possible to add tags to the hosts described inside the inventory?
My goal is to be able to run the ansible-playbook on specific host/group of hosts which has that specific tag e.g only on servers with tag 'Env=test and Type=test'
So for example when I run the playbook:
ansible-playbook -i hosts test.yml --extra-vars "Env=${test} Type=${test}"
I will pass the tags in the command and it will run only on the filtered hosts.
Thanks a lot!
Update:
Alternatively maybe doing something like in dynamic inventory? https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html#developing-inventory
[tag_Name_staging_foo]
[tag_Name_staging_bar]
[staging:children]
tag_Name_staging_foo
tag_Name_staging_bar
ansible ansible-2.x ansible-inventory
add a comment |
As the topic says, my question is if its possible to add tags to the hosts described inside the inventory?
My goal is to be able to run the ansible-playbook on specific host/group of hosts which has that specific tag e.g only on servers with tag 'Env=test and Type=test'
So for example when I run the playbook:
ansible-playbook -i hosts test.yml --extra-vars "Env=${test} Type=${test}"
I will pass the tags in the command and it will run only on the filtered hosts.
Thanks a lot!
Update:
Alternatively maybe doing something like in dynamic inventory? https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html#developing-inventory
[tag_Name_staging_foo]
[tag_Name_staging_bar]
[staging:children]
tag_Name_staging_foo
tag_Name_staging_bar
ansible ansible-2.x ansible-inventory
As the topic says, my question is if its possible to add tags to the hosts described inside the inventory?
My goal is to be able to run the ansible-playbook on specific host/group of hosts which has that specific tag e.g only on servers with tag 'Env=test and Type=test'
So for example when I run the playbook:
ansible-playbook -i hosts test.yml --extra-vars "Env=${test} Type=${test}"
I will pass the tags in the command and it will run only on the filtered hosts.
Thanks a lot!
Update:
Alternatively maybe doing something like in dynamic inventory? https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html#developing-inventory
[tag_Name_staging_foo]
[tag_Name_staging_bar]
[staging:children]
tag_Name_staging_foo
tag_Name_staging_bar
ansible ansible-2.x ansible-inventory
ansible ansible-2.x ansible-inventory
edited Jan 1 at 8:13
rivar_
asked Dec 31 '18 at 14:59
rivar_rivar_
298
298
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
To answer your question
Is it possible to add tags to hosts inside inventory to run the ansible-playbook on specific host/group of hosts?
No, tags apply ONLY to the tasks
When you apply tags: attributes to structures other than tasks, Ansible processes the tag attribute to apply ONLY to the tasks they contain. Applying tags anywhere other than tasks is just a convenience so you don’t have to tag tasks indivdually.
Hi @VladimirBotka thanks for the answer! But I bumted into this option: Static Groups of Dynamic Groups which seems like you can break your host group into child groups and the example uses the tags?(docs.ansible.com/ansible/latest/user_guide/…)
– rivar_
Jan 1 at 8:04
1
Hi @rivar_! This is misunderstanding. The "tags" in EC2 context is something completely different from tags.
– Vladimir Botka
Jan 1 at 10:25
Thanks a lot @VladimirBotka
– rivar_
Jan 2 at 12:02
add a comment |
Hosts don't have ansible "tags"; tasks have tags and they'e used to conditionally execute the tasks, not conditionally target hosts.
There's a few ways to conditionally target hosts, and the best way in my experience is ansible groups. Put the hosts you want to target in a group; then either target this group directly in a play:
- hosts: my_host_group
tasks: [ ... ]
Or limit the playook to a subset of the hosts targeted in a play:
ansible-playbook -l my_limited_hosts_group playbook.yaml
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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%2fstackoverflow.com%2fquestions%2f53988796%2fansible-is-it-possible-to-add-tags-to-hosts-inside-inventory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To answer your question
Is it possible to add tags to hosts inside inventory to run the ansible-playbook on specific host/group of hosts?
No, tags apply ONLY to the tasks
When you apply tags: attributes to structures other than tasks, Ansible processes the tag attribute to apply ONLY to the tasks they contain. Applying tags anywhere other than tasks is just a convenience so you don’t have to tag tasks indivdually.
Hi @VladimirBotka thanks for the answer! But I bumted into this option: Static Groups of Dynamic Groups which seems like you can break your host group into child groups and the example uses the tags?(docs.ansible.com/ansible/latest/user_guide/…)
– rivar_
Jan 1 at 8:04
1
Hi @rivar_! This is misunderstanding. The "tags" in EC2 context is something completely different from tags.
– Vladimir Botka
Jan 1 at 10:25
Thanks a lot @VladimirBotka
– rivar_
Jan 2 at 12:02
add a comment |
To answer your question
Is it possible to add tags to hosts inside inventory to run the ansible-playbook on specific host/group of hosts?
No, tags apply ONLY to the tasks
When you apply tags: attributes to structures other than tasks, Ansible processes the tag attribute to apply ONLY to the tasks they contain. Applying tags anywhere other than tasks is just a convenience so you don’t have to tag tasks indivdually.
Hi @VladimirBotka thanks for the answer! But I bumted into this option: Static Groups of Dynamic Groups which seems like you can break your host group into child groups and the example uses the tags?(docs.ansible.com/ansible/latest/user_guide/…)
– rivar_
Jan 1 at 8:04
1
Hi @rivar_! This is misunderstanding. The "tags" in EC2 context is something completely different from tags.
– Vladimir Botka
Jan 1 at 10:25
Thanks a lot @VladimirBotka
– rivar_
Jan 2 at 12:02
add a comment |
To answer your question
Is it possible to add tags to hosts inside inventory to run the ansible-playbook on specific host/group of hosts?
No, tags apply ONLY to the tasks
When you apply tags: attributes to structures other than tasks, Ansible processes the tag attribute to apply ONLY to the tasks they contain. Applying tags anywhere other than tasks is just a convenience so you don’t have to tag tasks indivdually.
To answer your question
Is it possible to add tags to hosts inside inventory to run the ansible-playbook on specific host/group of hosts?
No, tags apply ONLY to the tasks
When you apply tags: attributes to structures other than tasks, Ansible processes the tag attribute to apply ONLY to the tasks they contain. Applying tags anywhere other than tasks is just a convenience so you don’t have to tag tasks indivdually.
answered Dec 31 '18 at 16:48
Vladimir BotkaVladimir Botka
1,2981410
1,2981410
Hi @VladimirBotka thanks for the answer! But I bumted into this option: Static Groups of Dynamic Groups which seems like you can break your host group into child groups and the example uses the tags?(docs.ansible.com/ansible/latest/user_guide/…)
– rivar_
Jan 1 at 8:04
1
Hi @rivar_! This is misunderstanding. The "tags" in EC2 context is something completely different from tags.
– Vladimir Botka
Jan 1 at 10:25
Thanks a lot @VladimirBotka
– rivar_
Jan 2 at 12:02
add a comment |
Hi @VladimirBotka thanks for the answer! But I bumted into this option: Static Groups of Dynamic Groups which seems like you can break your host group into child groups and the example uses the tags?(docs.ansible.com/ansible/latest/user_guide/…)
– rivar_
Jan 1 at 8:04
1
Hi @rivar_! This is misunderstanding. The "tags" in EC2 context is something completely different from tags.
– Vladimir Botka
Jan 1 at 10:25
Thanks a lot @VladimirBotka
– rivar_
Jan 2 at 12:02
Hi @VladimirBotka thanks for the answer! But I bumted into this option: Static Groups of Dynamic Groups which seems like you can break your host group into child groups and the example uses the tags?(docs.ansible.com/ansible/latest/user_guide/…)
– rivar_
Jan 1 at 8:04
Hi @VladimirBotka thanks for the answer! But I bumted into this option: Static Groups of Dynamic Groups which seems like you can break your host group into child groups and the example uses the tags?(docs.ansible.com/ansible/latest/user_guide/…)
– rivar_
Jan 1 at 8:04
1
1
Hi @rivar_! This is misunderstanding. The "tags" in EC2 context is something completely different from tags.
– Vladimir Botka
Jan 1 at 10:25
Hi @rivar_! This is misunderstanding. The "tags" in EC2 context is something completely different from tags.
– Vladimir Botka
Jan 1 at 10:25
Thanks a lot @VladimirBotka
– rivar_
Jan 2 at 12:02
Thanks a lot @VladimirBotka
– rivar_
Jan 2 at 12:02
add a comment |
Hosts don't have ansible "tags"; tasks have tags and they'e used to conditionally execute the tasks, not conditionally target hosts.
There's a few ways to conditionally target hosts, and the best way in my experience is ansible groups. Put the hosts you want to target in a group; then either target this group directly in a play:
- hosts: my_host_group
tasks: [ ... ]
Or limit the playook to a subset of the hosts targeted in a play:
ansible-playbook -l my_limited_hosts_group playbook.yaml
add a comment |
Hosts don't have ansible "tags"; tasks have tags and they'e used to conditionally execute the tasks, not conditionally target hosts.
There's a few ways to conditionally target hosts, and the best way in my experience is ansible groups. Put the hosts you want to target in a group; then either target this group directly in a play:
- hosts: my_host_group
tasks: [ ... ]
Or limit the playook to a subset of the hosts targeted in a play:
ansible-playbook -l my_limited_hosts_group playbook.yaml
add a comment |
Hosts don't have ansible "tags"; tasks have tags and they'e used to conditionally execute the tasks, not conditionally target hosts.
There's a few ways to conditionally target hosts, and the best way in my experience is ansible groups. Put the hosts you want to target in a group; then either target this group directly in a play:
- hosts: my_host_group
tasks: [ ... ]
Or limit the playook to a subset of the hosts targeted in a play:
ansible-playbook -l my_limited_hosts_group playbook.yaml
Hosts don't have ansible "tags"; tasks have tags and they'e used to conditionally execute the tasks, not conditionally target hosts.
There's a few ways to conditionally target hosts, and the best way in my experience is ansible groups. Put the hosts you want to target in a group; then either target this group directly in a play:
- hosts: my_host_group
tasks: [ ... ]
Or limit the playook to a subset of the hosts targeted in a play:
ansible-playbook -l my_limited_hosts_group playbook.yaml
answered Jan 14 at 16:38
Dan FarrellDan Farrell
6,08911417
6,08911417
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53988796%2fansible-is-it-possible-to-add-tags-to-hosts-inside-inventory%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