"msg": "The task includes an option with an undefined variable. The error was: 'type' is undefined\n\nThe error appears to be in '/home/runner/ng_roles/elasticsearch/tasks/index_templates.yml': line 13, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Copy metricbeat index template to elasticsearch master pod\n ^ here\n"
}
not sure what is causing this error, there is no type option for this module
how can my local_path file be relative to my ansible role? Currently this file is in ansible-roles/$role/files/ but I am not sure how I can reference that, all the documentation makes it seems like this file needs to be a path on the localhost
Is this a typo in your code or just in your post? I presume you meant prefix_type, since dashes/hyphens are illegal characters in ansible’s variable names. If this is in your code, then I would try fixing that first.
Place the metricbeat_template.json file, if it is a static file, in roles/my_role/files/ or if it is a jinja2 template, in roles/my_role/templates. If it’s a jinja2 template, I would also append .j2 to the filename as a rule of thumb.
Then in your task, just reference the filename in your source parameter. Ansible will search valid locations for implicit paths, starting with the role’s files/templates (in this case, since Ansible will know it’s running a task in a role and which role to look for the file).
For e.g. since k8s_cp doesn’t support jinja2 templates (unless you use the lookup plugin to render it in the content: parameter instead of local_path:)
- name: Copy metricbeat index template to elasticsearch master pod
kubernetes.core.k8s_cp:
kubeconfig: "{{ context_file }}"
context: "{{ aks_name }}"
namespace: "{{ namespace }}"
pod: "{{ prefix_type }}-elasticsearch-master-0"
container: "{{ prefix_type }}-elasticsearch"
local_path: metricbeat_template.json # will find it in ./files/
remote_path: /tmp/ # will reuse the same filename in local_path to save under this directory
Edit: Using a jinja2 template:
- name: Copy metricbeat index template to elasticsearch master pod
kubernetes.core.k8s_cp:
kubeconfig: "{{ context_file }}"
context: "{{ aks_name }}"
namespace: "{{ namespace }}"
pod: "{{ prefix_type }}-elasticsearch-master-0"
container: "{{ prefix_type }}-elasticsearch"
content: "{{ lookup('template', 'metricbeat_template.json.j2') }}" # will find it in ./templates/
remote_path: /tmp/metricbeat_template.json # need to fully qualify the path since we're saving raw content to the destination instead of copying a source file
Your elasticsearch role doesn’t appear to be in a proper roles location. Your working directory (wherever your playbook lives) should have a roles directory (unless you want to “install” elasticsearch in /home/runner/.ansible/roles, /usr/share/ansible/roles or /etc/ansible/roles), and elasticsearch should be immediately under roles.
roles/elasticsearch/tasks/index_templates.yml should be able to find metricbeat_template.json implicitly as roles/elasticsearch/files/metricbeat_template.json
Then when your playbook references the role, nothing should need to fully qualify the role path.
As for your copy file size mismatch, it might be helpful if we can see the error output from the task. It’s such a small file that I’m not sure what the issue would be, but it could be something as simple as not enough storage space (ephemeral or otherwise) to copy the entire file.
there was no error from the copy, it ran fine. I removed the file from the pod and it’s now working as expected, the file gets copied in it’s entirety. I’ve re-ran the task and it’s getting copied fully each time so I can’t explain why that happened but it seems to be a one off issue. Thanks for your help!
I’ve now hit this issue a second time where the file is not being copied in it’s entirety. I’m thinking I should maybe file a bug on this. There is no error from the task that copies the file:
This sounds like a bug, even if there’s some quirky behavior resulting from your environment specifically. I recommend that you submit an issue to the collection and include a link back to this topic for reference.