# Ansible for deployment and one-off tasks

**URL:** <https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607>\
**Category:** Ansible Project\
**Created:** [October 3, 2013, 7:35pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607 "2013-10-03T19:35:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [October 3, 2013, 7:35pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/1 "2013-10-03T19:35:55Z")

</div>

Sometimes (not often) we need to do some one-off maintenance (like manually deleting some files, force removing a package) before a single deploy.  
Using ansible seems like it would be a great tool to do this.

for example:

## role/app/defaults/main.yml

deploy\_patch: !!null

## role/app/tasks/deploy.yml

- include {{ deploy\_patch }}  
when: deploy\_patch  
… (rest of deploy tasks go here)

When I need to patch something I would run ansible like  
`ansible-playbook ... -e "deploy_path=/path/to/20131003-patch.yml" --tags deploy`

Where on that run the tasks in the patch file would be included but not on normal deploy runs.  
It seems like the include syntax above is invalid, can anyone here think of a different way to go about the desired result or whether it would make sense to allow variable includes like this?

-John

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 3, 2013, 8:00pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/2 "2013-10-03T20:00:49Z")

</div>

Looks like this is the problem:

- include {{ deploy\_patch }}

Should be

- include: “{{ deploy\_patch }}”

Note that this variable will need to be defined every time, as because the when statement will be applied to each task within the include.

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [October 3, 2013, 8:12pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/3 "2013-10-03T20:12:21Z")

</div>

Yeah I think defaulting deploy\_patch to !!null will do the trick so that when  
it’s not passed in as an extra arg all of the included tasks will be  
skipped.

Even with the quotes it doesn’t seem to work with ansible 1.3.1

# test/tasks/main.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 3, 2013, 8:55pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/4 "2013-10-03T20:55:33Z")

</div>

Where is foo getting defined?

Not seeing it on -e and wanted to be sure.

Thanks!

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [October 3, 2013, 9:22pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/5 "2013-10-03T21:22:13Z")

</div>

I’m setting it in test/defaults/main.yml

This seems to work fine:

$ ansible-playbook -vvv -c local --limit “localhost,” ./test.yml -i “localhost,” -e “foo=monkey-patch.yml”

But when i set a default value and don’t pass in a -e option it fails.

Here is a complete test role with output:

# test.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 3, 2013, 10:35pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/6 "2013-10-03T22:35:06Z")

</div>

Roles and includes basically are the same thing, so that’s probably why there are not available to define a role path.

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [October 3, 2013, 10:40pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/7 "2013-10-03T22:40:10Z")

</div>

Interestingly for:

- include: “{{ foo }}”  
when: foo

if I set “foo: !!null” in defaults/main.yml I get:  
ERROR: file not found: /home/jarv/src/configuration/playbooks/roles/test/tasks/{{foo}}  
If I set it in vars/main.yml I get:  
ERROR: file not found: /home/jarv/src/configuration/playbooks/roles/test/tasks/None

Do you think this should get a bug report or is it too much of an edge case?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 4, 2013, 11:36am UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/8 "2013-10-04T11:36:36Z")

</div>

"when" does not apply to the include directive, this always happens, it  
applies to all tasks included.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 4, 2013, 1:16pm UTC](https://forum.ansible.com/t/ansible-for-deployment-and-one-off-tasks/13607/9 "2013-10-04T13:16:24Z")

</div>

Yup!

You might want to use “group\_by” conditionally, to create dynamic groups of places where this is true.
