Score:0

Running a local script on local host with Ansible

pm flag

I have a python script which is able to retrieve the IP adress of my remote node, and as a pre-task of my ansible playbook I would like to run this script and set the IP adress. Is there a command in Ansible which would allow me to do this ?

in flag
`delegate_to: localhost` along with `set_fact` should do the trick. For more details, more information about the script is needed.
Score:0
br flag

yes you can

- name: Run local script
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
    - name: Execute script
      command: /path/to/your/script.py
      register: script_output

    - name: Print script output
      debug:
        var: script_output.stdout

or as proxx mentioned, u can use delegate_to

- name: Run local script on remote host
  hosts: your_remote_node
  gather_facts: false
  tasks:
    - name: Execute script on control machine
      command: /path/to/your/script.py
      register: script_output
      delegate_to: localhost

    - name: Print script output
      debug:
        var: script_output.stdout
Score:0
ua flag

With delegate_to it is possible to control where an action is run.

Straight from the Ansible documentation:

---
- hosts: webservers
  serial: 5

  tasks:
    - name: Take out of load balancer pool
      ansible.builtin.command: /usr/bin/take_out_of_pool {{ inventory_hostname }}
      delegate_to: 127.0.0.1

This will run the command on the ansible host. There is really not much more to it!

Link to Ansible documentation on the topic.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.