Azure devops - ansible azure rm issue - azure-devops

I have an issue with running the pipeline, i'm trying to run ansible using the dynamic inventory azure_rm
does anyone has any idea how to fix this?
i get several message errors like the one below :
[WARNING]: * Failed to parse
/home/vsts/work/1/s/ansible/inventory/myazure_rm.yml with auto plugin: name
'azure_cloud' is not defined
[WARNING]: * Failed to parse
/home/vsts/work/1/s/ansible/inventory/myazure_rm.yml with yaml plugin: Plugin
configuration YAML file, not YAML inventory
[WARNING]: * Failed to parse
/home/vsts/work/1/s/ansible/inventory/myazure_rm.yml with ini plugin: Invalid
host pattern 'plugin:' supplied, ending in ':' is not allowed, this character
is reserved to provide a port.
[WARNING]: Unable to parse /home/vsts/work/1/s/ansible/inventory/myazure_rm.yml
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'
it is pretty much a simple inventory:
plugin: azure_rm
include_vm_resource_groups:
- rg-test
auth_source: auto
fail_on_template_errors: False
location: "france central"

Related

ansible dynamic inventory kubernetes

I am trying to use the kubernetes plugin in ansible to be able to use a dynamic inventory based on my k8 cluster. I have followed this doc https://docs.ansible.com/ansible/latest/scenario_guides/kubernetes_scenarios/k8s_inventory.html however i keep getting a failed to parse error.
# ansible-inventory --list -i k8s.yaml
[WARNING]: * Failed to parse /etc/ansible/k8s.yaml with ansible_collections.kubernetes.core.plugins.inventory.k8s plugin: Invalid value "kubernetes.core.k8s" for configuration option "plugin_type: inventory
plugin: ansible_collections.kubernetes.core.plugins.inventory.k8s setting: plugin ", valid values are: ['k8s']
[WARNING]: Unable to parse /etc/ansible/k8s.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
}
}
extract from ansible.cfg
# egrep -i "\[inventory\]|kubernetes" ansible.cfg
[inventory]
enable_plugins = kubernetes.core.k8s
k8s.yaml
# cat k8s.yaml
plugin: kubernetes.core.k8s
The error suggests that kubernetes.core.k8s is an invalid value and that valid values are ['k8s']. yet this is exactly whats in the documentation, I have tried all manor of altering the plugin name with no success.
Can anyone steer me on what i am missing here?
So I managed to get it working by editing /usr/lib/python3/dist-packages/ansible_collections/kubernetes/core/plugins/inventory/k8s.py it seems my version only listed k8s as a pluggin name, I replaced with, kubernetes.core.k8s and it worked
options:
plugin:
description: token that ensures this is a source file for the 'k8s' plugin.
required: True
choices: ['kubernetes.core.k8s']
I did plan to raise it as a PR on the project but seems this was already updated several months back so I must have just had outdated files.
https://github.com/ansible-collections/kubernetes.core/blob/60933457e81fcfa1000f556b2bc3425bbf080602/plugins/inventory/k8s.py#L27

Unable to view the contents of file in ansible managed nodes

I'm trying to view the contents of a file from managed node and control node, here I see the syntax works fine for localhost (172.17.254.200) but not for the remote hosts. Below is the task I have written using lookup / query plugin, can you please suggest the fix:
---
- name: Report Test
hosts: all
roles:
- patching
tasks:
- name: Display the Pre and Post check Differences
debug:
msg: "{{ query('file', '/tmp/check/{{ inventory_hostname }}_Comparison') }}"
Below is the output
TASK [patching : Display the Pre and Post check Differences] ***********************************************************************************************************
ok: [172.17.254.200] =>
msg:
- |-
free_m - YES
sysctl_all - YES
uptime - YES
[WARNING]: Unable to find '/tmp/check/172.17.254.207_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.207]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.207_Comparison'
[WARNING]: Unable to find '/tmp/check/172.17.254.208_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.208]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.208_Comparison'
Lookups are executed on Ansible controller (as pointed out by #Vladimir Botka). If you just want to view the contents of a file on remote hosts, you can cat the file through ansible and debug the stdout_lines.
- command: "cat /tmp/check/{{ inventory_hostname }}_Comparison"
register: file_cat
changed_when: false
- debug:
var: file_cat.stdout_lines
lookup and query "execute and are evaluated on the Ansible control machine."
Use slurp. Quoting:
This module returns an ‘in memory’ base64 encoded version of the file, take into account that this will require at least twice the RAM as the original file size.
For larger files use fetch. Quoting:
It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname.

Invalid characters were found in group names but not replaced ansible k8s

My k8s.yaml inventory file is:
plugin: k8s
connections:
- kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'
context: 'user1#testeks.us-east-1.eksctl.io'
ansible playbook:
test_new.yml
- hosts: localhost
tasks:
- name: Create a k8s namespace
k8s:
name: testing3
api_version: v1
kind: Namespace
state: present
Looks like the ansibleplaybook command is not picking up the inventory k8s.yaml.Also I am not sure why I am getting Warning invalid characters {'-' in group name warnings.
Please let me know if the above inventory file and ansible playbook files look good or are there anything I am missing?
ansible-playbook -vvvv -i k8s.yaml -vvv ./test_new.yml
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method
script declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method
Not replacing invalid character(s) "{'-', '9'}" in group name (909676E2B4F81625BF5994625D3353C9-yl4-us-east-1-eks-amazonaws-com)
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons)
Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons_pods)
Not replacing invalid character(s) "{'.', '/', '-'}" in group name (label_app.kubernetes.io/instance_aws-cluster-autoscaler)
I'm not sure where you got that you need the Kubernetes parameters specified in your inventory file. If you look at the k8s module documentation it says that kubeconfig and context are specified in the playbook or as environment variables.
Your inventory should look something like this:
all:
hosts:
host.where.can.access.the.kubeapiserver.com:
Then your playbook:
- name: Create a k8s namespace
k8s:
name: testing3
api_version: v1
kind: Namespace
state: present
kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml' 👈 this can replaced by the K8S_AUTH_KUBECONFIG env variable
context: 'user1#testeks.us-east-1.eksctl.io' 👈 this can replaced by the K8S_AUTH_CONTEXT env variable
Based on the formatting of your post, it looks like your inventory file contains improper syntax. It should look like this:
plugin: k8s
connections:
- kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'
context: 'user1#testeks.us-east-1.eksctl.io'
Remember that spaces are important.
For deprecation warnings, be sure to read up on these issues:
https://github.com/ansible/ansible/issues/56930
https://github.com/kubernetes-sigs/kubespray/issues/4830
Usage of hyphens in inventory group names was deprecated in Ansible 2.8 due to Python parser errors when using dot syntax. Auto-transformation can be disabled by adding force_valid_group_names = never to your Ansible config file. Similarly, deprecation warnings can be suppressed by adding deprecation_warnings = False though this is not recommended.

Is there any placeholder notation in mta.yaml that removes spaces from the CF org name parameter?

We are using mta to structure our application and deploying it using the SAP Cloud SDK Pipeline and Transport Management landscape.
In the mta.yaml, we are referencing the org (organization) parameter value using the placeholder notation ${org}.
The issue is that the org name contains spaces between the characters (viz. Sample Org Name) and that is causing error during the application deployment to Cloud Foundry.
We do not want to rename the org name.
Is there any other placeholder notation that removes the spaces between the characters?
We have observed that ${default-host} removes the spaces from the organization name but its scope is limited to only modules and not resources.
We need the substitution variable in the resources scope.
Appreciate if someone can help us here to resolve the issue.
Please find snippet of the mta.yaml and the error message.
resources:
- name: uaa_test_app
parameters:
path: ./xs-security.json
service-plan: application
service: xsuaa
config:
xsappname: 'test-app-${org}-${space}'
type: org.cloudfoundry.managed-service
Error Message:
Service operation failed: Controller operation failed: 502 Updating service "uaa_test_app" failed: Bad Gateway: Service broker error: Service broker xsuaa failed with: org.springframework.cloud.servicebroker.exception.ServiceBrokerException: Error updating application null (Error parsing xs-security.json data: Inconsistent xs-security.json: Invalid xsappname "Test-App-Sample Org Name-test": May only include characters 'a'-'z', 'A'-'Z', '0'-'9', '_', '-', '', and '/'.)

Parse error generating server stub with openapitools/openapi-generator-cli using OAS 3.0

I am trying to generate server code using openapitools/openapi-generator-cli which I installed globally using NPM.
When I run the command:
openapi-generator generate -i MyApi.yaml -g aspnetcore -o ./src
I get the following error:
[main] ERROR i.s.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
I have also tried converting my spec file to json and encountered the same error.
How can I resolve this error with parsing the yaml file?
I ran my spec file through the online editor at http://editor.swagger.io/ and found an error in my yaml (I forgot to add a parameter entry for a path with a parameter in the path). Once I fixed the error, the generator worked correctly.
So this was user error, though the error message could be better.