# break this up into tasks and roles and variables

**URL:** <https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656>\
**Category:** Ansible Project\
**Created:** [August 20, 2021, 8:58pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656 "2021-08-20T20:58:13Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 20, 2021, 8:58pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/1 "2021-08-20T20:58:13Z")

</div>

how do I break this play up into roles/tasks/variables etc…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 23, 2021, 2:06pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/2 "2021-08-23T14:06:31Z")

</div>

you are showing a playbook with a single task and no variables, there  
is not much to break up here

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 4:01am UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/3 "2021-08-24T04:01:01Z")

</div>

my variables are

ansibletestbucket12345  
arn:aws:kms:us-west-1:462518063038:key/f164e76a-f6f8-4773-84dc-053a44b2678d  
prod  
s3 bucket  
util  
32  
atomdomain

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 24, 2021, 8:02am UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/4 "2021-08-24T08:02:32Z")

</div>

Did you read the reply?

What do you want to achieve?  
What is the intention?  
Why do you say "break this play up into roles/tasks/variables etc."?

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 11:50am UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/5 "2021-08-24T11:50:21Z")

</div>

i want to reuse the role. i only want to modify the variables for future use

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 11:59am UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/6 "2021-08-24T11:59:20Z")

</div>

ok so here is what i have

s3\_bucket.yml

---

<div class="post-metadata">

**Author:** ![Jorge\_Rua1](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@Jorge\_Rua1](https://forum.ansible.com/u/Jorge_Rua1)\
**Post date:** [August 24, 2021, 12:08pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/7 "2021-08-24T12:08:38Z")

</div>

Splitting a single task into a role does not make much sense to me.

But if you want to go ahead with it, just pass any variables you are currently using in your task, to the role.

Something like this:

- include\_role:  
name: role-s3bucket-creator  
apply:  
delegate\_to: localhost  
vars:  
role\_var\_name1: “{{ foo }}”  
role\_var\_name2: “{{ bar }}”

Going forward I suggest you ellaborate a little bit more on your questions, so people can actually understand what are you trying to achieve.

Regards,

---

<div class="post-metadata">

**Author:** ![Jorge\_Rua1](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@Jorge\_Rua1](https://forum.ansible.com/u/Jorge_Rua1)\
**Post date:** [August 24, 2021, 12:12pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/8 "2021-08-24T12:12:47Z")

</div>

Remove the leading - character on the - hosts line.

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 12:24pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/9 "2021-08-24T12:24:04Z")

</div>

it is still not working.

yaml checker says ok

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [August 24, 2021, 12:28pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/10 "2021-08-24T12:28:33Z")

</div>

> it is still not working.

With a little effort a sensible mind would discover that hosts: doesn't belong into task files.

Just my two cents.

```
          Racke

```

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 12:56pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/11 "2021-08-24T12:56:47Z")

</div>

ok

corrected it

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 1:30pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/12 "2021-08-24T13:30:06Z")

</div>

any idea? why is sudo password needed?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [August 24, 2021, 1:40pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/13 "2021-08-24T13:40:15Z")

</div>

> any idea? why is sudo password needed?

Because you asked for that (become: yes)

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 1:41pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/14 "2021-08-24T13:41:25Z")

</div>

i dont have that in my pb.

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 2:33pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/15 "2021-08-24T14:33:23Z")

</div>

ok thanks a lot. finally got it working.

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [August 24, 2021, 2:36pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/16 "2021-08-24T14:36:43Z")

</div>

quick question. is there a way to quickly rollback ?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 24, 2021, 2:58pm UTC](https://forum.ansible.com/t/break-this-up-into-tasks-and-roles-and-variables/35656/17 "2021-08-24T14:58:39Z")

</div>

quick answer: no
