How to automate Cisco ios switch running-config backup to tftp server using ansible - ansible

I have tried
ios_command module to run command
"copy running-config tftp"
Next I have to provide ip of tftp server. Followed by destination file name.
I have tftp server running and I have ip address of it. But to provide the ip address and file name.
I have tried with sending
ios_command:
commands:
-copy running-config tftp
-ip of my tftp server.
It didn't worked
Can anyone help me?

- name: "Use of Ios commands"
ios_command:
commands:
- "copy running-config tftp:\n<your_ip_adresse>"
prompt: '[<your_destination_filename>]?'
answer: '\r'

Related

Mac won't connect to localhost server run from VirtualBox

My mac won't connect to localhost, I've tried with Safari and Mozilla, so it's not the browser, I tried other solutions I found on the internet, I ping 127.0.0.1 and it works correctly, if I run dscacheutil -q host -a name localhost I get the following:
name: localhost
ipv6_address: ::1
name: localhost
ip_address: 127.0.0.1
If I run apachectl configtest I get Syntax OK.
I've also read that my /etc/hosts might have been corrupted, this is how it looks like:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
I have no idea what else to try
EDIT: I'm trying to run an application (Hortonworks Sandbox) from a virtual machine (VirtualBox) in mac, I was advised to try port forwarding but this is what I see when I check the port forwarding in VirtualBox, seems like everything is in order:
I also tried to run Vagrant from VirtualBox and Mac couldn't connect to the localhost server when needed

Can we create a playbook to install a package in our own system?

I'm using Ubuntu Linux
I have created an inventory file and I have put my own system IP address there.
I have written a playbook to install the nginx package.
I'm getting the following error:
false, msg" : Failed to connect to the host via ssh: connect to host myip : Connection refused, unreachable=true
How can I solve this?
You could use the hosts keyword with the value localhost
- name: Install nginx package
hosts: localhost
tasks:
- name: Install nginx package
apt:
name: nginx
state: latest
Putting your host IP directly in your inventory treats your local machine as any other remote target. Although this can work, ansible will use the ssh connection plugin by default to reach your IP. If an ssh server is not installed/configured/running on your host it will fail (as you have experienced), as well as if you did not configure the needed credentials (ssh keys, etc.).
You don't need to (and in most common situations you don't want to) declare localhost in your inventory to use it as it is implicit by default. The implicit localhost uses the local connection plugin which does not need ssh at all and will use the same user to run the tasks as the one running the playbook.
For more information on connection plugins, see the current list
See #gary lopez answer for an example playbook to use localhost as target.

Set static IP on Centos7

I have a CentOS7 box that I need to change from DHCP to Static IP. I am using the ansible code below and I keep getting message. I have installed the required packages for this to work, so I dont think that is the issue.
"FAILED! => {"changed": false, "msg": "Error: Failed to modify connection 'System ens192': No such method 'Update2'\n", "name": "System ens192", "rc": 1}"
I know the ifname is "ens192" not sure about the conn_name. I did a "nmcli connection show" and a "nmcli device show" but none of them seem to work.
I have tried for the conn_name "ens192, System ens192, my-en192" and I get the same error message just with the different conn_names.
I would ultimately like to have these values set by the gathering facts procedure, but not sure how to do this?
- name: Add an Ethernet connection with static IP configuration
nmcli:
conn_name: ens192
ifname: ens192
type: ethernet
ip4: 192.0.2.100/24
gw4: 192.0.2.1
state: present
"nmcli connection show" and a "nmcli device show" but none of them seem to work
It should work.
Did you install dependancies for this module?
If not you can install them with ansible this way:
- name: install needed network manager libs
package:
name:
- NetworkManager-glib
- nm-connection-editor
- libsemanage-python
- policycoreutils-python
state: present
Or just yum install them.
When I run the nmcli commands, this is the output I get. I have tried to use on the conn_name: ens192 and System ens192 and both give me the same error message.
nmcli device show
GENERAL.DEVICE: ens192
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:50:56:87:FB:F1
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: System ens192
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/0
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 10.21.10.100/24
IP4.GATEWAY: 10.21.10.254
IP4.DNS[1]: 8.8.8.8
IP4.DNS[2]: 4.2.2.2
IP6.ADDRESS[1]:
IP6.GATEWAY: --
GENERAL.DEVICE: lo
GENERAL.TYPE: loopback
GENERAL.HWADDR: 00:00:00:00:00:00
GENERAL.MTU: 65536
GENERAL.STATE: 10 (unmanaged)
GENERAL.CONNECTION: --
GENERAL.CON-PATH: --
IP4.ADDRESS[1]: 127.0.0.1/8
IP4.GATEWAY: --
IP6.ADDRESS[1]: ::1/128
IP6.GATEWAY: --
[root#kamailio01 ~]# nmcli connection show
NAME UUID TYPE DEVICE
System ens192 2df1f002-52f2-4d9c-b7dd-7af061eceb34 ethernet ens192
In my work, I've just had a Jinja2 template and used the template module to overwrite the /etc/sysconfig/network-scripts/ifcfg-whatever file.

Using ping on localhost in a playbook

I am unable to run ping commands from a ansible host (using localhost, see below).
I built a simple playbook to run ping using the command module:
---
#
- name: GET INFO
hosts: localhost
tasks:
- name: return motd to registered var
command: "/usr/bin/ping 10.39.120.129"
register: mymotd
- name: debug output
debug: var=mymotd
However, I this error: "ping: socket: Operation not permitted"
Seems like there is a permissions issue. However, looking at the /usr/bin directory, it looks like ping would be executable to me:
"-rwxr-xr-x. 1 root root 66176 Aug 4 2017 ping",
I cannot become or use sudo, it seems like tower is locked down for that and I don't have the authority to change it either.
Anyone have any suggestions? What brought me to this, is that I am trying to run ping in a custom module and getting a similar issue.
Thanks
ping binary needs to have the SETUID bit set to be fully runable as a normal user, which is not the case on your server.
You need to run as root:
chmod u+s $(which ping)
If you don't have root access and cannot have this done by an admin, I'm affraid you're stuck... unless the server you are trying to ping is a machine you can manage with ansible.
In this later case, there is a ping module you can use. It is not ICMP ping as said in the doc. See if this can be used in your situation.
One of the numerous ref I could find about ping permissions: https://ubuntuforums.org/showthread.php?t=927709

hostname cannot resolved during installation of IBM private cloud ce

I installed IBM-Cloud-private-ce by following the guide https://www.ibm.com/support/knowledgecenter/SSBS6K_1.2.0/installing/install_containers_CE.html
But after I ran docker run -e LICENSE=accept --net=host -t -v "$(pwd)":/installer/cluster ibmcom/cfc-installer:1.2.0 install, I got the following error messages
task path: /installer/playbook/roles/check/tasks/main.yaml:78
fatal: [a.b.c.d] => Hostname should be resolved to a valid IP address
fatal: [a.b.c.e] => Hostname should be resolved to a valid IP address
I put the ip address as [a.b.c.d] just for confidential. Actually they are numbers here. These IP address are reachable.
By checking the ansible file, I noticed the following code
- name: Checking Hostname is resolvable
shell: ping -c 1 $(hostname) | awk -F'[()]' '{print $2;exit}'
args:
executable: /bin/bash
register: ip_out
- name: Validating Hostname is resolvable
fail: msg="Hostname should be resolved to a valid IP address"
when: ip_out.stdout in ['', '127.0.0.1', '127.0.1.1']
I found I cannot ping in the container as the image hasn't ping in it.
Is this the reason why I got the message? I appreciate if anyone could help on it.
Updated the question. Thanks #SBERENS
I tried on the 2.1.0 version and met the same issue: (for confidential reason, I used a.b.c.d as the IP address, actually the IP address are reachable)
My /etc/hosts is like the following:
127.0.0.1 localhost
127.0.1.1 e1.xx.yy.com e1
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
#puppet:
a.b.c.a puppet.xx.yy.com puppet
a.b.c.d e1.xx.yy.com e1
a.b.c.e e2.xx.yy.com e2
The cluster/hosts is like:
[master]
a.b.c.d
[worker]
a.b.c.e
[proxy]
a.b.c.e
#[management]
#4.4.4.4
The link you posted seems to be for older 1.2 level.
Please check that you are following the correct most updated installation instructions.
Latest version ICP 2.1 - CE are here:
https://www.ibm.com/support/knowledgecenter/SSBS6K_2.1.0/installing/install_ce.html
Can you please post your /etc/hosts file and the cluster/hosts file contents?
Your issue will occur in either 1.2 or 2.1.
The error is that the hostname e1.xx.yy.com resolves to a.b.c.d and 127.0.1.1. When this happens, the installer is enforcing the resolved IP to be something which is externally routable.
Is there a reason why you have the machine hostname defined on the local address in addition to a separate network IP?
Suggest removal of the line:
127.0.1.1 e1.xx.yy.com e1
from /etc/hosts. This can cause DNS confusion esp on Ubuntu.

Resources