Hi everyone,
I need to include a playbook which essentially contains a set of initialisation tasks for any set of variables passed to it. Like so:
include: upstart_common_init.yml
vars:
program_name: “{{ item.service_name }}”
program_config_options: “–config-file /etc/xyz/{{ item.service_conf }}”
system_user: “{{ system_user_name }}”
system_group: “{{ system_group_name }}”
service_home: “{{ system_home_folder }}”
with_items: some_services
when: >
inventory_hostname in groups[item.service_group] and
item.service_en == true
tags:
Where the some_services is a dictionary of services:
some_services:
{ service_name: abc, service_en: True, service_conf: abc.ini, service_group:abc_group }
{ service_name: def, service_en: True, service_conf: def.ini, service_group:def_group }
I know with_items isn’t supported with include so I get the following error:
ERROR: [DEPRECATED]: include + with_items is a removed deprecated feature, Please update your playbooks.
What would be a reasonable way to implement the above block of code?
Thanks,
J
Brian_Coca
(Brian Coca)
October 12, 2015, 10:56pm
2
actually, in 2.0 we 'resurrect' include + with_items. so it depends on
which version of ansible you are running.
Bas_Kamer
(Bas Kamer)
October 13, 2015, 9:40am
3
yes, however with ansible 2.0-beta1 I see the included task is uh, included. but any task defined in it are not executed.
a playbook such as;
vars:
mysql_databases:
{ name: stg_snd, collation: utf8_general_ci, encoding: utf8, replicate: 0, import_s3_backup: false}
{ name: dev_snd, collation: utf8_general_ci, encoding: utf8, replicate: 0, import_s3_backup: false }
{ name: prd_snd, collation: utf8_general_ci, encoding: utf8, replicate: 0, import_s3_backup: true }
tasks:
name: mysql | import databases from backup
include: “{{ playbook_dir }}/roles/provision.mysql/tasks/import_s3_backup.yml”
with_items: “{{ mysql_databases | list }}”
when: “{{ item.import_s3_backup | default(false) }} == true”
and this task file
the output is TASK [mysql | import databases from backup] ************************************
skipping: [s02.localhost] => (item={u’collation’: u’utf8_general_ci’, u’import_s3_backup’: False, u’replicate’: 0, u’name’: u’plhw_stg_sandalinos’, u’encoding’: u’utf8’}) => {“changed”: false, “item”: {“collation”: “utf8_general_ci”, “encoding”: “utf8”, “import_s3_backup”: false, “name”: “stg_snd”, “replicate”: 0}, “skip_reason”: “Conditional check failed”, “skipped”: true}
skipping: [s02.localhost] => (item={u’collation’: u’utf8_general_ci’, u’import_s3_backup’: False, u’replicate’: 0, u’name’: u’plhw_dev_sandalinos’, u’encoding’: u’utf8’}) => {“changed”: false, “item”: {“collation”: “utf8_general_ci”, “encoding”: “utf8”, “import_s3_backup”: false, “name”: “dev_snd”, “replicate”: 0}, “skip_reason”: “Conditional check failed”, “skipped”: true}
included: {{ playbook_dir }}/roles/provision.mysql/tasks/import_s3_backup.yml for s02.localhost => (item={u’collation’: u’utf8_general_ci’, u’import_s3_backup’: True, u’replicate’: 0, u’name’: u’prd_snd’, u’encoding’: u’utf8’})
PLAY RECAP *********************************************************************
s02.localhost : ok=1 changed=0 unreachable=0 failed=0
No ‘Boo’ is outputted.
I can place any string as the include argument (path) no error no different output. It will bravely tell me ‘included: non/existing/path/to/task.yml’, yes that is incorrect
Bas_Kamer
(Bas Kamer)
October 13, 2015, 9:43am
4