Ansible > url login check with some test - ansible

I want to check my application url by ansible. First I want to check url status and after that login with credentials and check some test like some contents after login.
But unable to do it.
- name: Check url
uri:
url: http://192.168.195.210/app
- name: login check
uri:
url: http://192.168.195.210/app
method: GET
user: Admin
password: admin
force_basic_auth: yes
status_code: 200
Let us know is it possible to do it?

The uri module can return the body of the call by enabling return_content. Register it to a variable and assert its contents. The first task in the question checks that /app returns 200 OK, which does not seem appropriate considering basic auth is required.
- name: Ensure wrong credentials are unauthorized
uri:
url: http://192.168.195.210/app
user: Admin
password: "not the admin password"
force_basic_auth: yes
status_code: 401
- name: Ensure admin can log in
uri:
url: http://192.168.195.210/app
user: Admin
password: "{{vault_admin_password}}"
force_basic_auth: yes
return_content: yes
register: login
- name: Ensure user is properly greeted when logged in
assert:
that:
- "'Welcome Admin' in login.content"

Related

How to connect to Rally from Ansible

I am trying to connect to Rally from Ansible. For this I am using uri module and also created an API key from Rally. My task:-
tasks:
- name: Get data
uri:
url: 'https://rally1.rallydev.com/slm/webservice/v2.0/subscription'
# headers:
# api_key: "myapikey"
user: myapikey
password:
follow_redirects: all
return_content: yes
status_code: 200
method: GET
register: get_data
- debug: var=get_data
But I am still getting error:-
"msg": "Status code was 401 and not [200]: HTTP Error 401: Full authentication is required to access this resource",
Not sure what I am doing wrong.
A simple way to prove that you have access would be to use curl on the command line and then script it via your favourite language to do something similar to the following:
curl --config options.txt
Where options.txt contains:
url https://rally1.rallydev.com/slm/webservice/v2.0/workspace?query=&fetch=true&start=1&pagesize=20
header = "ZSESSIONID: YOURAPIKEY"
You will see that the API key is used in a header variable ZSESSIONID. It works on my machine.....

How to fix IP Whitelist error in URI module of Ansible?

I am getting "IP not in white-list!" error when I run below playbook. How can I fix this error?
tasks:
- name: Create AD groups
uri:
url: https://server.uk.db.com:6001/governance/sims/users/jyotsnaparasjain#db.com/groups
method: POST
body: '{"nar":"123456-5", "env_list": ["PROD"], "roles": ["L1"], "approver3": "jyotsnaparasjain#gmail.com"}'
user: jyotsnaparasjain#gmail.com
body_format: json
status_code: 200
force_basic_auth: yes
headers:
X-Auth-Token: "token_comes_here"
validate_certs: no
register: create_ad_group
- name: Response of AD Group
debug:
var: create_ad_group.json
Error:
\"EXCEPTION\": \"IP not in white-list!!\"\n}\n"
It looks like this error message is an answer from a remote server. Try to talk to the administrator of the server server.uk.db.com to grant the access for your IP.
Otherwise, to get a better answer, please, provide the full error instead of small excerpt.

Ansible: ERROR! conflicting action statements

When I run my ansible file i get the following error:
conflicting action statements: user, uri
- name: Post Install watcher
hosts: director.0
gather_facts: no
tasks:
- name: Wait for Elastic Cluster to be ready
uri:
url: https://mlaascloudui.{{ lookup('env','ENV') }}.pre.mls.eu.gs.aws.cloud.vwgroup.com/api/v1/clusters/elasticsearch/{{elasticClusterDetails.elasticsea$
method: GET
user: admin
password: "{{rootpw.stdout}}"
force_basic_auth: yes
register: result
until: result['status']|default(0) == 412
retries: 60
delay: 10
- name: Install watcher
syntactically the code is correct. the user and password should be used for basic auth and I used similar code elsewhere and don't get any errors. What am I missing?
Remember your spacing. YAML is concern with the alignment of the spacing with the commands. Your "uri:" action should be aligned under "- name:". Ansible is thinking there are multiple actions associated with the "- name:" task.
Hope this helps.

Ansible 2.0 os_user Module Create User Error: Failed to list users

Im trying automate openstack istallation in ubuntu using ansible. For Identity service (keystone Installation),
My task is to create a user "demo", The command to do this is
openstack user create --domain default --password-prompt demo
and im using os_user module,
https://docs.ansible.com/ansible/os_user_module.html for creating user.
- os_user:
name: demo
password: DEMO_PASS
domain: default
wait: yes
state: present
environment: "{{ admin_openrc }}"
and the host is,
- hosts: controller
roles:
- install_keystone
tags:
- keystone
vars:
admin_openrc:
OS_PROJECT_DOMAIN_NAME: Default
OS_USER_DOMAIN_NAME: Default
OS_PROJECT_NAME: admin
OS_USERNAME: admin
OS_PASSWORD: ADMIN_PASS
OS_AUTH_URL: http://controller:35357/v3
OS_IDENTITY_API_VERSION: 3
OS_IMAGE_API_VERSION: 2
demo_openrc:
OS_PROJECT_DOMAIN_NAME: Default
OS_USER_DOMAIN_NAME: Default
OS_PROJECT_NAME: demo
OS_USERNAME: demo
OS_PASSWORD: DEMO_PASS
OS_AUTH_URL: http://controller:5000/v3
OS_IDENTITY_API_VERSION: 3
OS_IMAGE_API_VERSION: 2
But when im running the playbook,Im getting the following error,
"msg": "Failed to list users"
and the module fails with error.
when i run the command directly in terminal, its working fine.
Please help me with this.
Can you try:
vars:
auth_dict:
password: admin-pw
auth_url: http://your-url/your-version
username: admin
use auth paramter with os_user:
tasks:
- os_user:
auth: '{{ auth_dict }}'
name: your-user
password: your-password

Ansible get_url fails to download a protected by basic auth

I'm trying to download a protected file using HTTP from a remote server with the get_url module but the username password does not seem to get passed in the request and the task therefore fails.
I'm using Ansible 1.9.2
Here is the get_url definition I'm using:
- name: Downloading Artifact
get_url:
url: "http://myserver/somefile.tar.gz"
dest: "/home/jdoe/somefile.tar.gz"
url_username: "jdoe"
url_password: "mysecret"
mode: 0600
Here is the error I get:
failed: [myserver] => {"dest": "/home/jdoe/somefile.tar.gz", "failed": true,
"response": "HTTP Error 403: Forbidden", "state": "absent",
"status_code": 403, "url": "http://myserver/somefile.tar.gz"}
msg: Request failed
FATAL: all hosts have already failed -- aborting
Now, I tried to download the file using cURL and it works.
Any help is appreciated as I've struggling with this for 2 days.
You can use the uri module:
---
- hosts: hostname
tasks:
- name: "download file"
uri:
url: "http://somedomain.com/file.json"
method: GET
user: "{{ somedomain.user }}"
password: "{{ somedomain.password }}"
force_basic_auth: yes
dest: /tmp/somedomain.file.json
return_content: yes
If this doesn't work, probably it will have something to do with the httplib2 library version.
The problem is that your server does not return 401 status so that the httplib2 library can send over the BASIC authentication credentials afterwards. The solution is to upgrade to ansible >= 2.0 and use force_basic_auth: True so that the BASIC authentication credentials from the beginning.
I've had a similar issue in ansible 2.9.
Turns out curl was also getting HTTP 403 but showing content anyway. GET_URL module is just more strict.
For me, the issue was solved by switching from the default Apache welcome page to the smth custom made.

Resources