maven_artifact comman of ansible is not working in Rundeck - ansible

Objective:
Download the artifact jar from nexus to a Target server. I have already tried an attempt to download the jar via URL and not via maven_artifact, which was successful anyway. But wanted to try with maven_artifact command
Code in playbook:
---
- name: TestOfMavenArtifactCommand
hosts: Target_Server_Where_the_Jar_needs_to_be_downloaded
tasks:
- maven_artifact:
group_id: ab.cdef.group
artifact_id: artifact_name
repository_url: 'https://nexusUrl/repository/maven-snapshots'
dest: /folder/artifact_name.jar
username: user
state: present
mode: 0755
When I run the Rundeck job, it fails. The error is like:
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible-playbook
python version = 2.7.5 (default, Jun 11 2019, 12:19:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
Parsed /var/lib/rundeck/work/zxcv-folder-services/scpr-inventory_dev/dev/hosts.yml inventory source with ini plugin
[WARNING]: Ignoring invalid attribute: username
[WARNING]: Ignoring invalid attribute: artifact_id
[WARNING]: Ignoring invalid attribute: dest
[WARNING]: Ignoring invalid attribute: state
[WARNING]: Ignoring invalid attribute: mode
[WARNING]: Ignoring invalid attribute: repository_url
[WARNING]: Ignoring invalid attribute: group_id
PLAYBOOK: main.yml *************************************************************
1 plays in main.yml
fatal: [server00.companyxxx.dev ]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"artifact_id": null,
"attributes": null,
"backup": null,
"classifier": "",
"content": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"extension": "jar",
"follow": false,
"force": null,
"group": null,
"group_id": null,
"keep_name": false,
"mode": null,
"owner": null,
"password": null,
"regexp": null,
"remote_src": null,
"repository_url": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"state": "devsent",
"timeout": 10,
"unsafe_writes": null,
"username": null,
"validate_certs": true,
"version": "latest"
}
},
"msg": "group_id must be set"
}
to retry, use: --limit #/var/lib/rundeck/work/abcd-batch-services/scpr-servers-operations_dev/deploy-servers/tasks/main.retry
Followed the reference of this:
https://docs.ansible.com/ansible/latest/modules/maven_artifact_module.html

This appears to be just an indentation error. Try:
tasks:
- maven_artifact:
group_id: ab.cdef.group
artifact_id: artifact_name
repository_url: 'https://nexusUrl/repository/maven-snapshots'
dest: /folder/artifact_name.jar
username: user
state: present
mode: 0755

Related

Unable to create directory using ansible playbook

Steps to reproduce-
Ensure you have a VM running in VirtualBox (RHEL8)
Create a ansible galaxy collection
ansible-galaxy collection init myorg.mycollection
Navigate into the Roles Directory and execute following command
ansible-galaxy role init myrole
Add following code in main.yml inside the roles/myrole/tasks/main.yml
---
# tasks file for myrole
- name: Create /home/{{username}}/.ssh, if not exist
file:
path: "/home/{{username}}/.ssh"
state: directory
Create a play.yml file with following content
---
- name: Configure Development Workstation
hosts: my_user_name-rhel8
connection: local
debugger: on_failed
gather_facts: no
become_user: my_user_name
vars:
uname: "my_user_name"
roles:
- role: myorg.mycollection.myrole
username: "{{ uname }}"
build your collection with following command
ansible-galaxy collection build myorg/mycollection
install your collection with following command
ansible-galaxy collection install ./myorg-mycollection-1.0.0.tar.gz --force
run ansible playbook with following command
ansible-playbook play.yml -i my_user_name-rhel8, --ask-become-pass -vvv
Expected Result: The /home/username/.ssh folder should be created successfully.
Actual Result: The ansible fails with following result
[WARNING]: Platform darwin on host my_user_name-rhel8 is using the discovered Python interpreter at /usr/bin/python, but future
installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible/2.11/reference_appendices/interpreter_discovery.html for more information.
fatal: [my_user_name-rhel8]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"invocation": {
"module_args": {
"_diff_peek": null,
"_original_basename": null,
"access_time": null,
"access_time_format": "%Y%m%d%H%M.%S",
"attributes": null,
"follow": true,
"force": false,
"group": null,
"mode": null,
"modification_time": null,
"modification_time_format": "%Y%m%d%H%M.%S",
"owner": null,
"path": "/home/my_user_name/.ssh",
"recurse": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"state": "directory",
"unsafe_writes": false
}
},
"msg": "There was an issue creating /home/anchavan as requested: [Errno 45] Operation not supported: '/home/my_user_name'",
"path": "/home/my_user_name/.ssh"
}

Ansible Symbolic Link Task Role Failure

I am new to ansible and executing the following ansible task:
- name: Create symbolic links
file:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ jboss_usr }}"
group: "{{ jboss_grp }}"
state: link
with_items:
- { src: "/apps/etc/jboss", dest: "/etc/jboss" }
- { src: "/apps/var/log/jboss", dest: "/var/log/jboss" }
And I got the following error:
2018-12-21 21:27:23,469 p=15185 u=ex_sam | failed: [hostname.x] (item={u'dest': u'/etc/jboss', u'src': u'/apps/etc/jboss'}) => {
"changed": false,
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"content": null,
"delimiter": null,
"dest": "/etc/jboss",
"diff_peek": null,
"directory_mode": null,
"follow": true,
"force": true,
"group": "jboss",
"mode": null,
"original_basename": null,
"owner": "jboss",
"path": "/etc/jboss",
"recurse": false,
"regexp": null,
"remote_src": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": "/apps/etc/jboss",
"state": "link",
"unsafe_writes": null,
"validate": null
}
},
"item": {
"dest": "/etc/jboss-as",
"src": "/apps/etc/jboss"
},
"msg": "Error while linking: [Errno 13] Permission denied",
"path": "/etc/jboss-as",
"state": "absent"
}
I am trying to find out why the symbolic link creation failed.
I read the following:
https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#id6
I says the "changed" attribute is a boolean indicating if the task had to make changes.
But, there are lots of null parameters in the invocation:module_args elements of the json
Does that mean the values are really “null” or they are being set to a default value?
I have looked into the ansible documentation and I am not sure if the invocation:module_args null values are representative of the outcome of the trying to create the symbolic link i.e. are the null input or output of executing the tasks.
I think some of the nulls are defaults, but will appreciate some helpful comments on the possible relation between the json returned in my ansible error log and the actual "Error while linking: [Errno 13] Permission denied".
Thanks all for you anticipated help.
I think, is the permissions on /etc. So probably you need to add the option:
become: true
To your task.

Ansible to Proxmox returning 500 error

I am trying to use Ansible to provision some VMs on my newly set up Proxmox VE. I have installed proxmoxer and request with PIP on both my local Mac and Proxmox VE (Python 2 on Proxmox and Python 3 locally). I use Ansible 2.4.3.0, Proxmox version: 5.1-41.
I do have a vm with the id of 100, which was created from a Debian template, the vm is located on local-lvm (pve).
My full playbook can be found at: https://github.com/atwright147/ansible-contact-book-proxmox-provisioner, the specific task is pasted below:
---
- proxmox_kvm:
api_user: root#pam
api_password: REDACTED
api_host: pve
vmid: 100
state: current
When running this script via: ansible-playbook -vvv --connection=local -i hosts site.yml I get the following error:
The full traceback is:
File "/tmp/ansible_TDEJsZ/ansible_module_proxmox_kvm.py", line 1227, in main
current = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.current.get()['status']
File "/usr/local/lib/python2.7/dist-packages/proxmoxer/core.py", line 84, in get
return self(args)._request("GET", params=params)
File "/usr/local/lib/python2.7/dist-packages/proxmoxer/core.py", line 79, in _request
resp.content))
fatal: [192.168.0.22]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"acpi": true,
"agent": null,
"api_host": "pve",
"api_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"api_user": "root#pam",
"args": null,
"autostart": false,
"balloon": 0,
"bios": null,
"boot": "cnd",
"bootdisk": null,
"clone": null,
"cores": 1,
"cpu": "kvm64",
"cpulimit": null,
"cpuunits": 1000,
"delete": null,
"description": null,
"digest": null,
"force": null,
"format": "qcow2",
"freeze": null,
"full": true,
"hostpci": null,
"hotplug": null,
"hugepages": null,
"ide": null,
"keyboard": null,
"kvm": true,
"localtime": null,
"lock": null,
"machine": null,
"memory": 512,
"migrate_downtime": null,
"migrate_speed": null,
"name": null,
"net": null,
"newid": null,
"node": null,
"numa": null,
"numa_enabled": null,
"onboot": true,
"ostype": "l26",
"parallel": null,
"pool": null,
"protection": null,
"reboot": null,
"revert": null,
"sata": null,
"scsi": null,
"scsihw": null,
"serial": null,
"shares": null,
"skiplock": null,
"smbios": null,
"snapname": null,
"sockets": 1,
"startdate": null,
"startup": null,
"state": "current",
"storage": null,
"tablet": false,
"target": null,
"tdf": null,
"template": false,
"timeout": 30,
"update": false,
"validate_certs": false,
"vcpus": null,
"vga": "std",
"virtio": null,
"vmid": 100,
"watchdog": null
}
},
"msg": "Unable to get vm None with vmid = 100 status: 500 Internal Server Error: {\"data\":null}"
}
Ansible info:
ansible 2.4.3.0
config file = /Users/andy/Development/proxmox-playbooks/contact-book/ansible.cfg
configured module search path = ['/Users/andy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.6.4 (default, Jan 25 2018, 18:48:20) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)]
What am I doing wrong?
It turned out that I was making several mistakes here.
I should have been using the proxmox module rather than proxmox_kvm
I needed to use the storage param to set up the container in local-lvm e.g. storage: local-lvm
My final, working task looks like this:
- name: "Create a Linux Container (LXC)"
proxmox:
node: pve
api_user: root#pam
api_password: proxmox_password
api_host: pve
password: vm_password
hostname: vm.hostname.local
ostemplate: "local:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz"
storage: local-lvm
cores: 2
state: present

How to create a directory with particular SE Linux context on it

Here is what I have:
- name: Create directories that will be used as persistent volumes
become: yes
become_method: sudo
file:
path: /tmp/pv-{{ item }}
state: directory
mode: "g=rwx"
group: "root"
selevel: _default
seuser: _default
serole: _default
setype: svirt_sandbox_file_t
with_items:
- cassandra
- services
The two directories are correctly created, group a rights are ok. But the SE Linux context is wrong.
$ ll -dZ /tmp/pv-cassandra
drwxrwxr-x. 2 jkremser root unconfined_u:object_r:user_tmp_t:s0 40 Mar 9 15:19 /tmp/pv-cassandra
This is the part of the debugging output:
ok: [localhost] => (item=cassandra) => {
"changed": false,
"diff": {
"after": {
"path": "/tmp/pv-cassandra"
},
"before": {
"path": "/tmp/pv-cassandra"
}
},
"gid": 0,
"group": "root",
"invocation": {
"module_args": {
"backup": null,
"content": null,
"delimiter": null,
"diff_peek": null,
"directory_mode": null,
"follow": false,
"force": false,
"group": "root",
"mode": "g=rwx",
"original_basename": null,
"owner": null,
"path": "/tmp/pv-cassandra",
"recurse": false,
"regexp": null,
"remote_src": null,
"selevel": "_default",
"serole": "_default",
"setype": "svirt_sandbox_file_t",
"seuser": "_default",
"src": null,
"state": "directory",
"unsafe_writes": null,
"validate": null
},
"module_name": "file"
},
"item": "cassandra",
"mode": "0775",
"owner": "root",
"path": "/tmp/pv-cassandra",
"size": 80,
"state": "directory",
"uid": 0
}
What am I doing wrong? My OS is Fedora 25.
If I use the copy module, instead of the file, that has almost the same parameters, it throws this error:
Aborting, target uses selinux but python bindings (libselinux-python) aren't installed
After installing the libselinux-python package, it works! So it looks like the file module silently swallows the error and does what it can do :( I can't depend on the fact that user has the libselinux-python package installed.
I'll probably call the chcon myself as a shell command or add the package as a prerequisite:
- name: Install the libselinux-python package
package:
name: libselinux-python
state: present

Make ansible run a task in a playbook multiple times based on variables

I am trying to use the Ansible URI Module to log into multiple webpages and check the environments are up and working.
At the moment, i want it to just log into 2 webpages (Peoplesoft envs), but i would like a vars file that i can add to each time i want to to check a new page.
This is what i have so far, but it doesnt seem to log into both pages, just 1 of them....any help woould be appreciated.
Playbook -
---
- name: Run Selenium Test Scripts
hosts: local
vars_files:
- /etc/ansible/uri_module/vars_uri.yml
tasks:
- name: Installing URI dependancy
yum: name=python-httplib2.noarch state=present
- name: Log into Webpage
uri:
url: http://{{appserver}}:{{port}}/{{dbname}}/signon.html
method: POST
body: "name={{userid}}&password={{password}}&enter=Sign%20in"
with_file: /etc/ansible/uri_module/vars_uri.yml
Vars file
---
- { name: 'dog', appserver: 'st1920', port: '8100', dbname: 'dbdog', userid: 'user', password: 'pass' }
- { name: 'cat', appserver: 'st1921', port: '8300', dbname: 'dbcat', userid: 'user', password: 'pass' }
Output with -vvvv
ok: [local] => {"changed": false, "content_language": "en-US", "content_length": "1831", "content_type": "text/html", "date": "Thu, 13 Oct 2016 11:45:23 GMT", "invocation": {"module_args": {"backup": null, "body": "name=user&password=pass&enter=Sign%20in", "body_format": "raw", "content": null, "creates": null, "delimiter": null, "dest": null, "directory_mode": null, "follow": false, "follow_redirects": "safe", "force": null, "force_basic_auth": false, "group": null, "method": "POST", "mode": null, "owner": null, "password": null, "regexp": null, "remote_src": null, "removes": null, "return_content": false, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "status_code": [200], "timeout": 30, "url": "http://st1921:8300/dbcat/signon.html", "user": null, "validate_certs": true, "with_file": "/etc/ansible/uri_module/vars_uri.yml"}, "module_name": "uri"}, "last_modified": "Wed, 13 Aug 2014 11:42:42 GMT", "redirected": false, "server": "WebSphere Application Server/7.0", "status": 200}
Using the vars file, i want it to log into the dog environment, tell me its there, log into the cat environment, tell me its there. Then if i have a horse, frog, or what ever environment, i can keep adding to the vars file without adding to or changing the playbook. At the moment it only logs into cat and i dont know why.
Have i goen down the right route with this? Is there a better way of doing it? With it not giving an error, im struggling to figure out the issue!
Thanks.
I don't think it is possible to use with_file like that.
It would be cleaner to store the vars_uri dictonaries in a list like this:
---
vars_uri:
- { name: 'dog', appserver: 'st1920', port: '8100', dbname: 'dbdog', userid: 'user', password: 'pass' }
- { name: 'cat', appserver: 'st1921', port: '8300', dbname: 'dbcat', userid: 'user', password: 'pass' }
and loop over it with with_items like this:
---
# Run Selenium Test Scripts
hosts: local
vars_files:
- /etc/ansible/uri_module/vars_uri.yml
tasks:
- name: Installing URI dependancy
yum: name=python-httplib2.noarch state=present
- name: Log into Webpage
uri:
url: http://{{ item.appserver }}:{{ item.port }}/{{ item.dbname }}/signon.html
method: POST
body: "name={{ item.userid }}&password={{ item.password }}&enter=Sign%20in"
with_items: vars_uri

Resources