A.W.E.S.O.M.E.!!!!!!!!
I have no opportunity to try now (ansible can be run fom smartphone?? :) ) but do you know if it works with with_items statement?
Eg:
- roles:
- { role : 'application', project: $item }
with_items: $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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
However, when I saw the syntax, my first reaction was "eyebrow raising".
Why that mustache-enclosed sort of thing ?
Hi,
I would just like to check if I get it correctly, that this "roles" are
just a shortcut for those who do not want to explicitly write out
everything
and actually do not add any new feature different to what
already exists?
It is therefore a less flexible and explicit, but otherwise exactly the same
thing as doing:
]nd group_vars (what doesn't make much sense to me). This is
actually the purpose of (...)
--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hi,
I am also in the process of reorganizing things to roles and the approach I am currently using (also influenced by Puppet) is:
# web.yml
---
- hosts: all
roles:
## Application roles
- role: app1
install: yes
config: yes
deploy: yes
test: yes
# app1/tasks/main.yml
---
- include: install.yml
only_if: ${install}
- include: config.yml
only_if: ${config}
- include: deploy.yml
only_if: ${deploy}
- include: test.yml
only_if: ${test}
Is this the way it is meant to be used? Or am I again trying to go in the wrong direction?
Greetings,
gw
I have a role, "application" that contains tasks/main.yml and deploy.yml. The main.yml is the base configuration we want to constantly manage and deploy.yml is (unexpectedly) the deployment steps for updates. With the current roles setup I can only get main.yml included, I believe. Would you envision us putting the deployment steps into main.yml and perhaps tagging them and using tags with roles to select functionality, or expanding it so we can do: role: 'application:deploy' or something to select other yaml.
I suspect there's a more ansible way to do this and I'm still just so influenced by Puppet that I can't see what it is.
Hi,
I am also in the process of reorganizing things to roles and the approach I am currently using (also influenced by Puppet) is:
# web.yml
## Application roles
---
- hosts: all
roles:
- role: app1
install: yes
config: yes
deploy: yes
test: yes
# app1/tasks/main.yml
---
- include: install.yml
only_if: ${install}
- include: config.yml
only_if: ${config}
- include: deploy.yml
only_if: ${deploy}
- include: test.yml
only_if: ${test}Is this the way it is meant to be used? Or am I again trying to go in the wrong direction?
Greetings,
gw
I have a role, "application" that contains tasks/main.yml and deploy.yml. The main.yml is the base configuration we want to constantly manage and deploy.yml is (unexpectedly) the deployment steps for updates. With the current roles setup I can only get main.yml included, I believe. Would you envision us putting the deployment steps into main.yml and perhaps tagging them and using tags with roles to select functionality, or expanding it so we can do: role: 'application:deploy' or something to select other yaml.
This is not true.In the middle of main.yml all you have to do is:---- include: deploy.yml tags=deployAnd that will include deploy.yml and auto-tag everything in it with the tag "deploy"
--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hm, if it would be possible to access current tags as a variable one could do things like:
- debug: msg="foo"
only_if: 'deploy' in $tags
tags: deploy
This would execute if and only if --tags=deploy is given.
Or is it already possible to access hosts, user, tags in playbooks/task lists?
Greetings,
gw
I mean: It will run only if "--tags deploy" is given, otherwise it will skip this step. Eg. if you do not pass any --tags or pass other --tags, the task will be skipped. It would function as a default skip policy if the right tag is not specified.
Anyway, it was just a thought...
Greetings,
gw
The last piece that still feels missing to me (at least for my use case) is the templates and files. With the new roles structure the default location for these is relative to the role directory. This works fine when the template as is can be sufficiently represented with various jinja interpolations. And for files its okay when the file is model/role specific and not app+environment relevant. However I have use cases where the app+environment can(/may need to) override the whole template, and/or potentially use its own file/* ref'd in the playbook. Would it make sense to lookup templates and files first relative to the hosts file, then fallback to role location?
This is something I do today which allows the app to own its own templates & files (pulled from their git repo), if desired, via first_available_file and some path hackery. But it seems to make sense to have this capability 'built in' where the templates/files default to the roles subdir but can be overriden relative to the 'inventory' if necessary.
--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
- name: copy operationcopy: src=$item dest=/tmp/roles_test1.txtfirst_available_file:- {{vars.inventory_dir}}/files/foo.txt- foo.txt- name: template operationtemplate: src=$item dest=/tmp/roles_test2.txtfirst_available_file:- {{vars.inventory_dir}}/templates/foo.j2- foo.j2notify:- blippy
Hi,
What about the following (untested) approach of default values that is implemented as a hack, but could be part of the core:
# playbook.yml
---
- hosts: all
roles:
- role: foo
tmpl: /alternative/templates/foo.j2
var1: overriden value
# foo/tasks/main.yml
---
- name: template operation
template: src={{ item }} dest=/etc/foo
with_first_found:
- "{{ tmpl }}"
- default.j2
- name: set default value with a shell hack
shell: test -n "{{ var1 }}" && echo "{{ var1 }}" || echo "default value"
register: used_var1
- name: some other operation
other: param={{ used_var1 }}
With this approaches everything about which default values should be overriden is still present in the playbook, not in inventory files. The template operation is obvious.
Instead of the hack to get the right thing into "used_var1" a "with_first_defined" could be defined. It would behave like "with_first_found" (first_available_file)
but instead of looking for files existance it checks if the value is fully defined/resolved and does not contain any unresolved variables (does not contain "{{" or "$\w+").
The above example with something like this:
- name: some other operation
other: param={{ item }}
with_first_defined:
- "{{ var1 }}"
- default value
Thoughts?
Greetings,
gw
If a variable wants to be used throughout a role, then its default values and overrides could be stored back into a variable like this (although a better alternative to debug module would be nice):
- debug: msg="{{ item }}"
register: var1
with_first_found:
- "{{ var1 }}"
- foo
- name: access the variable whose default value can be overriden
shell: echo {{ var1.results[0].msg }}
Greetings,
gw
I've been refactoring my app playbook over the week end and the roles are great, one thing that could be nice is to have the an option to have detailed roles logging so I'd know where variables and tasks are coming from just by looking at stout.I'm thinking something like adding "--roles-logging" to a playbook run to getPLAY [hosts] ****Roles: db_server, commonRoles details:db_servervars:foobar,files:-TASK: [making sure mysqld is up] ***Role: db_servers--This as remote as it gets from being a critical feature but it'd be a nice addition =)My 2cts to the roles discussionJ.
--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.