Set static IP on Centos7 - ansible

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.

Related

Ansible Automation Platform 2.2.1 fails with "system hostname cannot be localhost"

I keep running into the following error while installing Ansible Automation Platform 2.2:
TASK [ansible.automation_platform_installer.preflight : Ensure hostname on nodes with receptor installed is not localhost] ***
fatal: [172.16.10.13]: FAILED! => {"changed": false, "msg": "The system hostname cannot be localhost, receptor requires it to be set to something other than localhost"}
The inventory file contents:
[automationcontroller]
172.16.10.13
[automationcontroller:vars]
peers=execution_nodes
ansible_user=root
ansible_ssh_private_key_file="path to my key file"
Example inventory file from Red Hat installation guide:
[automationcontroller]
127.0.0.1 ansible_connection=local
[database]
database.example.com
[all:vars]
admin_password='<password>'
pg_password='<password>'
pg_host='database.example.com'
pg_port='5432'
pg_database='awx'
pg_username='awx'
registry_url='registry.redhat.io'
registry_username='<registry username>'
registry_password='<registry password>'
Installation with both fails with the same error.
Basic networking topology in an ip4 system consists of the total ip4 address space less certain specific adress blocks and individual addresses.
The localhost/localnet block at 127.n.n.n is routable, but only to other addresses in that block, none of which are routable beyond the confines of the local host environment.
Hence the name ‘localhost’.
Since it is impossible to network on an address space that is unrouteable to any network, i.e., literally any other host, you will find it a prerequisite activity to fully configure a proper network in which all collaborative network contributors are all routable with each other.
Apparently you are supposed to use the fqdn.
On rhel 9:
sudo hostname your-hostname
[automationcontroller]
your-hostname.example.com
[automationcontroller:vars]
peers=execution_nodes
ansible_user=root
ansible_ssh_private_key_file="path to my key file"

Is it possible to manage a device instead of a connection with Ansible 'nmcli' module?

I have to apply the following configuration on several hosts via Ansible:
nmcli device modify "device_name" ens192 ipv6.method "disabled"
I wanted to use the nmcli module instead of a command as it is cleaner. But from what I found on the documentation and forums the nmcli module manage only connections.
Apart from recovering all connections associated to an interface and modifying each one using Ansible nmcli module I could not find a way to do it. This solution beeing, in my opinion, uglier than using command module I will stick with command.
Any informed comment or suggestion would be appreciated.
For the sake of precision the current code used to disable ipv6 if networkmanager is used:
- name: get service facts
service_facts:
- name: Disable ipv6 with network manager
become: yes
command: "/bin/nmcli device modify {{ ansible_default_ipv4.interface }} ipv6.method 'disabled'"
when: ansible_facts.services["NetworkManager.service"] is defined
changed_when: false
I am not sure if I understand your question fully since there is no example what you have tried, problem description, description of your system, used versions, confguration or error messages.
Regarding
I wanted to use the nmcli module instead of a command as it is cleaner
and according the documentation of the module nmcli there is a parameter ifname
The interface to bind the connection to.
The connection will only be applicable to this interface name.
A special value of '*' can be used for interface-independent connections.
The ifname argument is mandatory for all connection types except bond, team, bridge, vlan and vpn.
This parameter defaults to conn_name when left unset for all connection types except vpn that removes it.
So looking at the CLI output of nmcli device show
GENERAL.DEVICE: eth0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: AB:CD:EF:01:02:03
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: eth0
...
and since conn_name obviously points to GENERAL.CONNECTION, wouldn't that parameter
ifname for GENERAL.DEVICE not be that one which you are looking for?
The Examples are showing also the usage of ifname together with conn_name.
Furthermore ipv6.method disabled isn't available in example in RHEL 7, but as of 8.
- name: Make sure IPv6 is disabled
shell:
cmd: nmcli conn mod eth0 ipv6.method disabled
when: ansible_distribution == 'RedHat' and ansible_distribution_major_version == '8'

How to automate Cisco ios switch running-config backup to tftp server using 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'

force Static IP on VM creation

I have an ansible script that connects to my Vcenter and builds out a VM. This works great assuming the network it will be built on has DHCP enabled. I am building mostly Centos 7 VM's on a network that does not have DHCP enabled meaning static IP's. The VM gets built, but then I am stuck logging into each VM manually and assigning the IP.
How can I tell CentOS to use a specific IP?
I am familiar with kickstart, but not sure how to trigger the install to pickup a ks file. (I know I can create a custom ISO, but I dont want to create a custom ISO for each VM I built.)
I have tried using the following flags on ansible VMware_guest module, but no luck.
Any Suggestions??
vmware_guest:
network:
type: static
ip: 192.168.1.5
mask: 255.255.255.0
gateway: 192.168.1.1
Please try using netmask instead of mask.
vmware_guest:
network:
name: "{{ network_name }}"
type: static
ip: 192.168.1.5
netmask: 255.255.255.0
gateway: 192.168.1.1

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