For example, given the files

shell> ssh admin@test_11 cat /tmp/.env
SMTPPORT: 5432
POPPORT: 5431
PGPORT: 5433

shell> ssh admin@test_12 cat /tmp/.env
SMTPPORT: 4432
POPPORT: 4431
PGPORT: 4433

shell> ssh admin@test_13 cat /tmp/.env
SMTPPORT: 3432
POPPORT: 3431
PGPORT: 3433

Fetch the files and declare the variables you need

shell> cat pb.yml
- hosts: test_11,test_12,test_13
  vars:
    env_file: /tmp/.env
    env_dest: "{{ playbook_dir }}/env_dest"
    my_env_file: "{{ [env_dest, inventory_hostname, env_file]|
                     join('/') }}"
    my_ports: "{{ lookup('file', my_env_file)|from_yaml }}"
    pg_service_port: "{{ my_ports.PGPORT + 1 }}"
  tasks:
    - fetch:
        src: "{{ env_file }}"
        dest: "{{ env_dest }}"
    - debug:
        var: pg_service_port

give (abridged)

ok: [test_11] => 
  pg_service_port: '5434'
ok: [test_12] => 
  pg_service_port: '4434'
ok: [test_13] => 
  pg_service_port: '3434'

-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20220916184429.2cc0a3a3%40gmail.com.

Attachment: pgpfcnV3G_KVu.pgp
Description: OpenPGP digital signature

Reply via email to