Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ansible to grab local ipv4 addresses to determine "local" connection #15

Open
craig8 opened this issue Dec 15, 2023 · 1 comment
Open
Assignees
Labels
enhancement New feature or request

Comments

@craig8
Copy link
Contributor

craig8 commented Dec 15, 2023

Local connections should have ansible_connection local and the ip address associated with it.

all:
  hosts:
    substation1:
      ansible_host: 127.0.0.1
      ansible_connection: local
      volttron_home: volttron_home1

This is how a local connection is built within the ansible inventory.yml file. Then running

ansible-playbook -K -i inventory.yml  volttron.deployment.host_config

will install the sudo user requirements for the base system of volttron.

Local host ipv4 addresses.

---
- hosts: localhost
  connection: local
  tasks:
    - debug: var=ansible_all_ipv4_addresses
    - debug: var=ansible_default_ipv4.address

This is one way to get the ipv4 addresses from the system.

~/.volttron_installer/platforms$ ansible-playbook localhost.yml 
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ***********************************************************************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] ***************************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "ansible_all_ipv4_addresses": [
        "172.17.0.1",
        "10.1.0.7",
        "172.18.0.1"
    ]
}

TASK [debug] ***************************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "ansible_default_ipv4.address": "10.1.0.7"
}
@craig8 craig8 added the enhancement New feature or request label Dec 15, 2023
@craig8
Copy link
Contributor Author

craig8 commented Dec 15, 2023

You can also use

import socket
socket.gethostbyname(socket.gethostname())

To get an ip address for the current system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants