How to set-up playbook level Environment variable after a few tasks

86 views
Skip to first unread message

Arundhati Bhende

unread,
Mar 26, 2022, 10:58:34 PM3/26/22
to ansible...@googlegroups.com

I need to set a playbook level Environment variable after executing some tasks.  The variable needs to be set-up separately on each server by reading a file on the server – I am told I should use slurp, but do not know how to use it to define playbook level environment variable.

 

Can someone help?

 

This is the current version of the playbook

 

 

- name: server properties

  hosts: kafka_broker

  vars:

    ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"

    ansible_host_key_checking: false

    date: "{{ lookup('pipe', 'date +%Y%m%d-%H%M%S') }}"

    copy_to_dest: "/export/home/kafusr/kafka/secrets"

    server_props_loc: "/etc/kafka"

    secrets_props_loc: "{{ server_props_loc }}/secrets"

 

  environment:

    CONFLUENT_SECURITY_MASTER_KEY: "”

 

  tasks:

 

    - name: Create a directory if it does not exist

      file:

        path: "{{ copy_to_dest }}"

        state: directory

        mode: '0755'

 

    - name: Find files from "{{ server_props_loc }}"

      find:

        paths: /etc/kafka/

        patterns: "server.properties*"

        # ... the rest of the task

      register: etc_kafka_server_props

 

    - name: Find files from "{{ secrets_props_loc }}"

      find:

        paths: /etc/kafka/secrets

        patterns: "*"

        # ... the rest of the task

      register: etc_kafka_secrets_props

 

    - name: Copy the files

      copy:

        src: "{{ item.path }}"

        dest: "{{ copy_to_dest }}"

        remote_src: yes

      loop: "{{ etc_kafka_server_props.files + etc_kafka_secrets_props.files }}"

 

 

Need help is setting up CONFLUENT_SECURITY_MASTER_KEY after the copy files task to read the a file from secrets directory using slurp, and have it avaibale at playbook level

 

Regards

Rilindo Foster

unread,
Mar 28, 2022, 10:57:40 AM3/28/22
to ansible...@googlegroups.com
So you are saying that you want:

CONFLUENT_SECURITY_MASTER_KEY be set?
- That value be persistent through the remainder of the playbook run?

Rilindo Foster - Cloud Reliability Architect


-- 
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CBF647EC-2D0F-4C25-82DD-E5D14A55FB7F%40prudential.com.


This email and its attachments are confidential and may be privileged.  Any unauthorized use or disclosure is prohibited.  If you receive this email in error, please notify the sender and permanently delete the original without forwarding, making any copies or disclosing its contents. NextCapital is a brand name representing NextCapital Group, Inc. and its subsidiaries, NextCapital Software, Inc. and NextCapital Advisers, Inc. 

Arundhati Bhende

unread,
Mar 28, 2022, 12:32:43 PM3/28/22
to ansible...@googlegroups.com

Yes.  But the value will be different on each of the target machines and can be determined after the copy  tasks are executed

Rilindo Foster

unread,
Mar 28, 2022, 1:13:51 PM3/28/22
to ansible...@googlegroups.com
Alright. My thought would be to register the master key as a fact in one play:

register:  some_confluent_value

And you set the environment variable on the next play that needs it.

- name: some confluent operation
  command: do something
  environment:
    CONFLUENT_SECURITY_MASTER_KEY: "{{ some_confluent_value }}"
  register: output
  changed_when: output.rc = 0


Rilindo Foster - Cloud Reliability Architect

Arundhati Bhende

unread,
Mar 28, 2022, 1:18:47 PM3/28/22
to ansible...@googlegroups.com

But, this would mean, I have to set it as environment in all the subsequent plays, right?  Not at the playbook level?

Reply all
Reply to author
Forward
0 new messages