Hi James, You may consider to use tags with include: http://docs.ansible.com/playbooks_tags.html
- include: deploy.yml tags=deployment Then, to perform deployment only: ansible-playbook example.yml --tags "deployment" And to perform everything else except deployment: ansible-playbook example.yml --skip-tags "deployment" The downside is you have to explicitly disable deployment tag for default run. Probably not much of an issue if used in script. On Friday, March 14, 2014 1:34:55 PM UTC-7, James Goodhouse wrote: > > I'd like to be able to run a role and, by default, exclude the code > deployment portion. I'd also like to be able to deploy the code without > running any other tasks. > > I could include a line in the main.yml file for my project role that would > only include the deploy.yml file when the deploy_code variable is true. > Something similar to below: > > - include: deploy.yml > when: "deploy_code" > > To deploy code, I would run a command like the following: > > ansible-playbook site.yml --extra-vars "deploy_code=true" > > The problem with this is that my site.yml file has several other entries > besides just my project role. The same is true for my project role's > main.yml – it contains other includes besides the deploy.yml. So if run the > above command, yes my code will deploy, but every other task will also run, > which I don't want to have happen. > > Does that make things clearer at all? > > On Friday, March 14, 2014 12:33:48 PM UTC-7, Michael DeHaan wrote: >> >> "The problem with that is that code deployment would be accompanied by >> all of the other tasks for provisioning the server, which is no bueno." >> >> I don't understand this part, can you elaborate? >> >> >> On Fri, Mar 14, 2014 at 3:30 PM, James Goodhouse <[email protected]>wrote: >> >>> I'm aware that I can do that, and have been thinking I might try to >>> implement some sort of variable to determine if I include my deploy.yml >>> file. This solution would work in that code wouldn't deploy unless I >>> explicitly set that variable via the command line. The problem with that is >>> that code deployment would be accompanied by all of the other tasks for >>> provisioning the server, which is no bueno. >>> >>> >>> On Friday, March 14, 2014 10:33:51 AM UTC-7, Michael DeHaan wrote: >>> >>>> So the task file roles/foo/tasks/main.yml is always loaded, however >>>> this pattern is common: >>>> >>>> main.yml: >>>> >>>> ---- >>>> - include: debian.yml >>>> when: "ansible_os_family == 'Debian'" >>>> >>>> - include: redhat.yml >>>> when: "ansible_os_family == 'RedHat'" >>>> >>>> - include: common.yml # all the time without conditionals. >>>> >>>> Hope this helps! >>>> >>>> >>>> >>>> >>>> >>>> On Fri, Mar 14, 2014 at 1:25 PM, James Goodhouse <[email protected]>wrote: >>>> >>>>> When specifying a role to use in a playbook, is it possible to target >>>>> a different file other than main.yml? I ask because I'm struggling to >>>>> find >>>>> the proper way to layout a playbook and role for my project. >>>>> >>>>> Currently I have roles created for common tasks like nginx, mysql, >>>>> varnish, etc. I also have a role created specifically for my project. >>>>> Inside that role I handle things like installing project specific things >>>>> like APC, memcache, etc. These are each handled by a separate file that >>>>> is >>>>> included in the main.yml. I also have a file for deployment that is also >>>>> included in the main.yml. However, I don't really want to have code >>>>> deploy >>>>> each time I provision a server. >>>>> >>>>> My thought was to create a deploy.yml file in the root and somehow >>>>> include the role for the project, but just the deploy portion. >>>>> >>>>> How are people handling this with their projects? >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ansible Project" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> To post to this group, send email to [email protected]. >>>>> >>>>> To view this discussion on the web visit https://groups.google.com/d/ >>>>> msgid/ansible-project/445571b4-e587-4216-83fe- >>>>> a8252d72c576%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/445571b4-e587-4216-83fe-a8252d72c576%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ansible Project" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/ansible-project/1d7937f5-42dd-40ef-962b-a7e40a828227%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/1d7937f5-42dd-40ef-962b-a7e40a828227%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a95f89be-ea37-4bfb-902a-0687d69359dd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
