In one of my playbooks I start a service and poll for its status before moving onto the next task like the following:
- name: Poll for service status
uri:
url: http://some-service/status
register: response
until: response.status == 200
retries: 12
delay: 10
This logs a message each time it queries the URL which looks like
FAILED - RETRYING: TASK: Poll for service status
Is there a way to customise this message? Specifically remove the word FAILED.
After grepping around, I found the "FAILED - RETRYING" message in the default output callback (read about callbacks here). That means you can change the callback in ansible.cfg to something that suits your needs- or make your own. You can even search the code for v2_runner_retry to see the various outputs.
For instance, here's what stdout_callback=oneline returns. There are no "retrying" messages even at -vv. It still says "FAILED" but that's because it actually failed.
ansible-playbook -vvi localhost, p.yml
ansible-playbook 2.4.1.0
config file = /opt/app/ansible.cfg
configured module search path = ['/opt/app/library']
ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.5.2 (default, Sep 14 2017, 22:51:06) [GCC 5.4.0 20160609]
Using /opt/app/ansible.cfg as config file
1 plays in p.yml
META: ran handlers
localhost | FAILED! => {"attempts": 3,"changed": false,"content": "","failed": true,"msg": "Status code was not [200]: Request failed: <urlopen error [Errno -2] Name or service not known>","redirected": false,"status": -1,"url": "http://some-service/status"}
Aside from setting it in ansible.cfg the documentation implies it can be done in a role. I have no idea how.
As #techraf said, the Ansible folks are pretty good at reviewing pull requests.
Related
I am working on a project using ansible AWX. In this project I have a check to see if all my microk8s pods are in the state running. Before I installed AWX I was testing all my plays on my linux vm. The following play worked fine on my linux vm but does not seem to work in ansible awx.
- name: Wait for pods to become running
hosts: host_company_01
tasks:
- name: wait for pod status
shell: kubectl get pods -o json
register: kubectl_get_pods
until: kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == ["Running"]
timeout: 600
AWX gives me the following respons
[WARNING]: an unexpected error occurred during Jinja2 environment setup: unable
to locate collection community.general
fatal: [host_company_01]: FAILED! => {"msg": "The conditional check 'kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == [\"Running\"]' failed. The error was: template error while templating string: unable to locate collection community.general. String: {% if kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == [\"Running\"] %} True {% else %} False {% endif %}"}
I have looked at the error message and tried different possible solutions but without any effect.
First thing I tried was looking for the community.general collections in the ansible galaxy collection list. After I saw that it was found I tried downloading it once again, but this time with sudo. The collection was installed. After running my workflow template, the error message popped up again.
Second thing was trying to use different Execution environments, I thought that this was not going to make any difference but tried it anyways since someone online fixed a similar issue by changed EE.
Last thing I tried was trying to find a way around this play by building a new play with different commands. Sadly I was not able to build an other play that did what the original one did.
Since I can not build a play that fits my needs I came back at the error message to try and fix it.
I'm trying to deployement an Openstack infrastracture multi node with kolla-ansible on Ubuntu 20.04.4.
ansible 4.10.0
ansible-core 2.11.11
kolla-ansible 13.0.1
when I execute command:
kolla-ansible -i /etc/kolla/multinode pull
or
kolla-ansible -i /etc/kolla/multinode deploy
I'm getting error:
fatal: [controller]: FAILED! => {"msg": "template error while templating string: No filter named 'select_services_enabled_and_mapped_to_host'.. String: {{ lookup('vars', (kolla_role_name | default(project_name)) + '_services') | select_services_enabled_and_mapped_to_host }}"}
fatal: [compute01]: FAILED! => {"msg": "template error while templating string: No filter named 'select_services_enabled_and_mapped_to_host'.. String: {{ lookup('vars', (kolla_role_name | default(project_name)) + '_services') | select_services_enabled_and_mapped_to_host }}"}
I have 1 deployment Node, 1 controller, 1 compute Node
Doesn't seems like a pull-issue based in the error-message. Seems like another configuration-problem with your Neutron. The default-multi-node config requires 3 controller. I don't exactly know your multi-node config for kolla-ansible, but when you only want 1 controller and 1 compute you can do something different:
Use the all-in-one-file for your setup. Should be in path kolla-ansible/ansible/inventory/all-in-one. Modify this file by replacing the localhost in the [compute]-section with the name of the host, where the compute should be created and remove the ansible_connection=local. This always worked for me, when I created a test-deployment with 1 controller and X compute-nodes.
Only in case you want the controller not on the host, where you execute the kolla-ansible, then replace all other localhost by the name of your controller-node and of course remove the ansible_connection=local everywhere.
Only the be sure: Don't forget to write the name of the host with it's ip-address in the /etc/hosts-file on the node, where you execute the kolla-ansible run.
Firstly, what's the result of kolla-ansible prechecks -i multinode_or_all-in-one command?
Dive into this method select_services_enabled_and_mapped_to_host of kolla-ansible project, you will find some clues. The method's return dependent by service_enabled and service_mapped_to_host
So, there are two step to clear your problem:
1, check the service enabled setting in /etc/kolla/globals.yml and kolla-ansible/ansible/group_vars/all.yml.
You can use this file(globals.yml) to override any variable throughout Kolla. Additional options can be found in the 'kolla-ansible/ansible/group_vars/all.yml' file.
2, check the host inventory in multinode or all-in-one file whether consistent with the really information or not.
Or everything is OK, I think you should redeploy it refer to kolla-ansible quickstar.
I have a task in my ansible playbook, that downloads a java archive from a github url.
The task is here:
- name: Download Jar Plugin
get_url:
url: https://GitHub-URL/plugins-1.0.5.jar
dest: /app/plugins/
There's no mention of checksum, yet it gives this error:
fatal: [host]: FAILED! => {"changed": false, "msg": "attempted to take checksum of directory: /app/plugins/plugins-1.0.5.jar"}
anyone has any idea about this? Is there any workaround to make it download this java archive?
First of all GitHub is not the right location to keep binaries. Github does not allow us to store a single file greater than 100 MB in most cases. You you should have binaries kept in either a physical server or any cloud storage and pull it from there.
Now, if you are really inclined to follow this bad practise I suggest you to create an equivalent unix curl first to do that. If you have an existing curl command to do that share that with us or simply use ansible shell module as a starting point. You can also try increasing timeouts as default is 10 secs only. Here's a snippet where timeout is set to 200 seconds.
- name: Download Jar Plugin
get_url:
url: https://GitHub-URL/plugins-1.0.5.jar
dest: /app/plugins/
timeout: 200
Try adding checksum argument as below:
- name: Download Jar Plugin
get_url:
url: https://GitHub-URL/plugins-1.0.5.jar
dest: /app/plugins/
timeout: 200
checksum: <yourchecksum>
Hope this helps as per your error.
I'm trying to capture the status HAProxy running on hosts.
I cannot figure out how to capture a debug from a task into a logfile as this shows the host name and status.
Using ansible 2.7.
Debug:
"haproxystatus.results.0.status.SubState": "dead",
"item": "hostnamedisplayedhere",
"my_idx": 0
No errors as such, cannot workout how to print/capture the debug into a logfile.
Any suggestions are appreciated.
When I try to clone a repo using windows domain credentials the backslashes are removed.
git: repo="http://DOMAIN\\user:password#server/repo"
dest=/srv/clone
version=develop
The error:
failed: [x.x.x.x] => {"cmd": ["/usr/bin/git", "ls-remote", "http://DOMAINuser:password#server/repo", "-h", "refs/heads/develop"], "failed": true, "rc": 128}
stderr: fatal: Authentication failed for 'http://DOMAINuser:password#server/repo/'
msg: fatal: Authentication failed for 'http://DOMAINuser:password#server/repo/'
FATAL: all hosts have already failed -- aborting
It looks like the escape is not working?
As far as I know, active directory authentication is orthogonal to the auth scheme you can use with the HTTP method in git. Thus, DOMAIN\\USER is simply the user string that your HTTP client (in your case, git) sends to the server. \ might look strange to the client, though. Have you tried \\\\?
This may seem funny, but I've lost enough time with Ansible escaping to justify it. Try defining a var (in some constant-appropriate place) like this backslash: "\\" and use it in templates like this, backslash*2.
At the very least you get consistency among direct uses in "{{ .. }}" and indirect uses in filters, like "{{ ... | some_filter('...') }}.