What does this "ansible -m ping all" mean? - ansible

ansible -m ping all
Why am I getting the same warnings and Errors when I tried running my Playbook? (starfish.yml)
So, that means: My Playbook is Right? But something important is Not. What is that?
Please Help...Thank You.
With Hope,
Prabhakaran
The following are the Warnings and Errors:
/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init_.py:44: CyptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
[WARNING]: * Failed to parse /etc/ansible/hosts with yaml plugin: We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: No JSON object could be decoded Syntax Error while loading YAML. expected '<document start>', but found '[' The error appears to be in '/etc/ansible/hosts': line 4, column 1, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: ] [starfish] ^ here
[WARNING]: * Failed to parse /etc/ansible/hosts with ini plugin: need more than 2 values to upack
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

I think you need to follow this doc https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html to build your ansible inventory.

Related

Ansible AWX returns error: template error while templating string: unable to locate collection community.general

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.

Kolla ansible images pull error on ubuntu 20.04

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.

How to execute linux command of helm using ansible modules?

I'm running this command:
- name: Save to tmp/charts
shell: '{{helm_cli_path}}/helm --kubeconfig {{kube_config}} install {{install-name}} {{helm_chart}}/ --dry-run --debug > {{charts_dir}}/{{install_name}}.yaml'
to store helm gerenated yamls using shell module for all helm charts, which is a generalization of this command:
helm1 install <chart-name> <chart-path> --dry-run --debug > tmp/<chart-name>.yaml
But I'm getting error:
fatal: [console.sb]: FAILED! => {"msg": "The task includes an option
with an undefined variable. The error was: Unable to look up a name or
access an attribute in template string ({{helm_cli_path}}/helm
--kubeconfig {{kube_config}} install {{install-name}} {{helm_chart}}/ --dry-run --debug > {{charts_dir}}/{{install_name}}.yaml).\nMake sure your variable name does not contain invalid characters like '-':
unsupported operand type(s) for -:
I have made sure that all variables in {{ }} are correct and defined at correct places.
Please suggest me the correct yaml task description / suitable ansible module to be used here.

Error running playbook with encrypted group_vars

I am trying to run a playbook with a file that has been encrypted using ansible-vault. However, I get the following error:
ERROR! Syntax Error while loading YAML.
could not find expected ':'
The error appears to have been in 'inventories/group_vars/main_server': line 41, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
Content of vault file:
me#server:ansible$ cat inventories/group_vars/main_server
$ANSIBLE_VAULT;1.1;AES256
...
Command I'm running:
ansible-playbook -i inventories/group_vars/main_server --extra-vars "target=my_target" playbook.yml --ask-become-pass --ask-pass --vault-password-file vault_pwd.txt
vault_pwd.txt is populated with the required password. I have been encrypting/decrypting as I develop my playbook. For instance, the shell script with the encrypting command:
ansible-vault encrypt inventories/group_vars/main_server --vault-password-file vault_pwd.txt
Edit #1
Version of Ansible:
me#server:ansible$ ansible --version
ansible 2.7.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/me/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
The error you're seeing...
ERROR! Syntax Error while loading YAML.
could not find expected ':'
The error appears to have been in 'inventories/group_vars/main_server': line 41, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
...is a YAML syntax error. Ansible is probably complaining about an actual syntax error in the unencrypted content (and if you're lucky, the line referenced in the error message is in fact the one with the error).

Error: Module unable to decode valid JSON on stdin. Unable to figure out what parameters were passed

I'm trying to write a new ansible module in python.
Playbook:
---
- hosts: localhost
gather_facts: no
connection: local
tasks:
- name: db_configurator
db_configurator: global_rpm='Test' user_home=/users/xpiwrk1/swjain
Module code:
# Initializing the module here which takes as input the required parameters from the playbook.
module = AnsibleModule(argument_spec=dict(
global_rpm=dict(default=None),
user_home=dict(default=None),
),
supports_check_mode=True)
global_rpm = module.params['global_rpm']
user_home = module.params['user_home']
The module is working absolutely fine when I'm running the module directly with python executable giving the input in required json parameters as command line args.
python db_configurator.py '{"ANSIBLE_MODULE_ARGS": { "global_rpm": "core.abp.amdocs.test:test_rpm", "user_home": "/users/xpiwrk1/swjain" }}'
However while running through playbook everytime I'm getting the below error. Anyone having any idea?
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Error: Module unable to decode valid JSON on stdin. Unable to figure out what parameters were passed"}
After comparison to some other modules with similar functionality. I found out the problem was with the way I imported AnsibleModule.
Replaced
AnsibleModule = ansible.module_utils.basic.AnsibleModule
with
from ansible.module_utils.basic import *
And module seems to work fine after this, but still in some of the forums I read that this way of importing (from ansible.module_utils.basic import *) is depcreated. Though it solved my problem for now, I'm not sure what should be the permanent fix.

Resources