I am trying to deploy kypo cyber range and am following its official guide. While deploying the whole range using ansible-playbook, I am stuck on above error:
TASK [docker : install prerequisites] ******************************************************************
fatal: [192.168.211.208]: FAILED! => {"changed": false, "msg": "Failed to update apt cache: unknown reason"}
I have manually checked apt-get update which initially gave me a notification of:
N: Skipping acquire of configured file 'stable/binary-i386/Packages' as repository 'https://download.docker.com/linux/ubuntu focal InRelease' doesn't support architecture 'i386'
I followed this to add [amd=64] to repository which cleaned the error. Now apt-get update runs with without any warnings or errors, but ansible-playbook keeps on generating this error.
I changed the verbosity level and got:
fatal: [192.168.211.208]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"allow_unauthenticated": false,
"autoclean": false,
"autoremove": false,
"cache_valid_time": 0,
"deb": null,
"default_release": null,
"dpkg_options": "force-confdef,force-confold",
"force": false,
"force_apt_get": false,
"install_recommends": null,
"name": [
"apt-transport-https",
"ca-certificates"
],
"only_upgrade": false,
"package": [
"apt-transport-https",
"ca-certificates"
],
"policy_rc_d": null,
"purge": false,
"state": "present",
"update_cache": true,
"update_cache_retries": 5,
"update_cache_retry_max_delay": 12,
"upgrade": null
}
},
"msg": "Failed to update apt cache: unknown reason"
}
How can I fix this?
In Kypo CRP, while playing the ansible playbook the error was actually coming from one of the instances of openstack which I found out by increasing verbosity in command -vvvv. Everything was fine with the host machine. So I look for changes in instances and the root cause was there was no internet access. Once I managed to connect them to external world, the error went away.
Related
$ ansible --version
ansible 2.10.8
Per Oracle VM VirtualBox 6.1 Silent Install (How-To Guide), I should be able to install VirtualBox silently like this
C:\temp> VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot
and if I run the above command in a Windows command prompt, it succeeds and installs VirtualBox.
Now I do this in Ansible
- name: "Install {{ artifact_filename }}"
win_package:
path: "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe"
arguments: "--silent --ignore-reboot"
state: present
and I get this when I run the playbook with the task.
fatal: [10.227.x.x]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"arguments": "--silent --ignore-reboot",
"chdir": null,
"client_cert": null,
"client_cert_password": null,
"creates_path": null,
"creates_service": null,
"creates_version": null,
"expected_return_code": [
0,
3010
],
"follow_redirects": "safe",
"force_basic_auth": false,
"headers": null,
"http_agent": "ansible-httpget",
"log_path": null,
"maximum_redirection": 50,
"password": null,
"path": "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe",
"product_id": null,
"provider": "auto",
"proxy_password": null,
"proxy_url": null,
"proxy_use_default_credential": false,
"proxy_username": null,
"state": "present",
"url_method": null,
"url_password": null,
"url_timeout": 30,
"url_username": null,
"use_default_credential": false,
"use_proxy": true,
"username": null,
"validate_certs": true,
"wait_for_children": false
}
},
"msg": "unexpected rc from 'C:\\temp\\VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot': see rc, stdout, and stderr for more details",
"rc": 1,
"reboot_required": false,
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
}
What am I missing? TIA.
I RTFM'd the win_package documentation. It says regarding the arguments option
arguments This is only used for the msi, msp, and registry providers.
So I do this instead
- name: "Install VirtualBox"
win_command: "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot"
If anyone has a better answer I'm all eyes.
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"
}
I have posted recently some examples of ansible playbooks tested and running as expected with the CLI and which stop working as soon as imported in AWX. here is another example:
- name: empty known_hosts
file:
state: absent
path: /root/.ssh/known_hosts
Here is the execution with the CLI:
TASK [configure-admin : empty known_hosts]
**************************************************************************************************
changed: [localhost]
and here is what happened in AWX:
TASK [configure-admin : empty known_hosts]
*************************************
fatal: [localhost]: FAILED! => {"changed": false, "gid": 0, "group": "root", "mode": "0644", "msg":
"unlinking failed: [Errno 116] Stale file handle: '/root/.ssh/known_hosts' ", "owner": "root",
"path": "/root/.ssh/known_hosts", "size": 34932, "state": "file", "uid": 0}
I have googled a lot looking for what might be causing this "Stale file handle" error. I found different posts talking about NFS mount points, but this doesn't have anything to do with my context.
I have a playbook with lineinfile. I need to capture the failure.
When I use register the failed ones of lineinfile are not being capture also the success one does not have enough information like a general register values. (Eg. there is no rc code, stdout or anything)
I need to capture the hosts on which the lineinfile task failed.
Please let me know if there is any method to achieve the requirement.
lineinfile:
path: /test
regexp: "^host"
line: "host myhost 127.0.0.1"
state: present
register: result
I am trying capture this message that is displayed in the verbose but unable to capture it with a register so that I can use the when condition and say when rc == 257 it is to be marked as failed.
fatal: [examplehost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"content": null,
"create": false,
"delimiter": null,
"directory_mode": null,
"firstmatch": false,
"follow": false,
"force": null,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "HOST example.something 127.0.0.1",
"mode": null,
"owner": null,
"path": "/test/my",
"regexp": "^HOST",
"remote_src": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"state": "present",
"unsafe_writes": null,
"validate": null
}
},
"msg": "Destination /test/my does not exist !",
"rc": 257
I don't understand your complaint; lineinfile: is going to ensure that line appears in the target file, and will only use the regexp: bit to assist it in placing the line. If the file does not have a line that starts with host, then lineinfile: will just append the line: to the bottom of the file, and cheerfully report that it did so in result.msg:
changed: [host0] => {"backup": "", "changed": true, "msg": "line added"}
changed: [host1] => {"backup": "", "changed": true, "msg": "line replaced"}
I keep getting this error when try create ProxMox containers using Ansible. Has anyone know how to fix this? Im trying to create Proxmox VE cluster containers. Uses LXD containers.
Here is my playbook
- hosts: proxmox
user: root
tasks:
- name: Test container
proxmox:
vmid: 777
node: 'pve'
api_user: 'root#pam'
api_password: 'admin'
api_host: 'node1'
password: '123456'
hostname: 'example.org'
ostemplate: 'local:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz'
Here is complete Ansible debug report
The full traceback is:
File "/tmp/ansible_p2azl7/ansible_module_proxmox.py", line 325, in <module>
from proxmoxer import ProxmoxAPI
fatal: [proxmox]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"api_host": "node1",
"api_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"api_user": "root#pam",
"cores": 1,
"cpus": 1,
"cpuunits": 1000,
"disk": "3",
"force": false,
"hostname": "example.org",
"ip_address": null,
"memory": 512,
"mounts": null,
"nameserver": null,
"netif": null,
"node": "pve",
"onboot": false,
"ostemplate": "local:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"pool": null,
"pubkey": null,
"searchdomain": null,
"state": "present",
"storage": "local",
"swap": 0,
"timeout": 30,
"unprivileged": false,
"validate_certs": false,
"vmid": "777"
}
},
"msg": "proxmoxer required for this module"
}
Any help is appreciated and thanks in advance.
Install proxmoxer on proxmox machine.
Or otherwise explain, what is your expectation for trying to run it without the library. You might be running it on a different target than you intended.