---- hosts: localhostgather_facts: noenvironment:MYVAR: "TEST1"tasks:- shell: echo "$MYVAR"register: mytest- debug:msg:- "Ansible MYVAR = {{mytest.stdout}}"- "Exported MYVAR = {{lookup('env', 'MYVAR')}}"
export MYVAR=TEST2;ansible-playbook ~/devansible/playbooks/mytestPLAY [localhost] ***************************************************************TASK [shell] *******************************************************************changed: [localhost]TASK [debug] *******************************************************************ok: [localhost] =>msg:- Ansible MYVAR = TEST1- Exported MYVAR = TEST2PLAY RECAP *********************************************************************localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
--
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/1a126537-a388-4a2a-81dc-108aa74ef27d%40googlegroups.com.
In my test, the target host is localhost, the same place that the lookup runs. But the lookup call was only to provide a demonstration of what is happening here and will not be used in my actual code.
Ansible uses some form of SSH (Paramiko, directly calling ssh, etc.), and that mechanism uses the value contained within SSH_AUTH_SOCK to determine how to talk to ssh-agent. But it is using the shell version of SSH_AUTH_SOCK, not the version that I have set within my Ansible playbook. I need a way to inform the SSH mechanism to use the Ansible version of SSH_AUTH_SOCK, not the shell version (preferred), or I need a way to push the Ansible version into the shell version (not as preferred).
Is there a way to do either of those?
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ansible-project/W0z5aMfhqDM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ansible-proje...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v9a4L-cpT6MkKn4RTsND8QguR89qVD%3DtVm3F0tEbPJSjA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/VE1PR06MB63524B96F5545F064EA39AFC9E3C0%40VE1PR06MB6352.eurprd06.prod.outlook.com.
You are missing the point. I am not trying to set SSH_AUTH_SOCK on the target host. I am trying to set it on the Ansible host, so that the SSH mechanism on the Ansible host can use the value of SSH_AUTH_SOCK to connect to the ssh-agent that is running on the Ansible host. The target host is not involved at this point; it is all still local on the Ansible host. Once the SSH mechanism has connected to the local ssh-agent, it can use the SSH key that is contained within the ssh-agent to establish a connection to the target host. But the SSH mechanism is using the wrong version of SSH_AUTH_SOCK. I need a way to inform it of the Ansible version, or to override the value in the shell version with the Ansible version.
When I use the shell command on the Ansible host (delegate_to: localhost) to execute ssh-add, ssh-add uses the Ansible version of SSH_AUTH_SOCK to connect to ssh-agent. But if I try to run a task on a target, the SSH mechanism that connects to the target host is clearly using the shell version of SSH_AUTH_SOCK.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v-yXH7F3Zo1FBQq5pDMPUxo5G1mRvJmsqjtK3JQyXAkGg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/VE1PR06MB63522E11EC557DA9123FFB2B9E3C0%40VE1PR06MB6352.eurprd06.prod.outlook.com.
FOUND IT!!!
I added this to the playbook:
- name: Test connection
command:
id
vars:
ansible_ssh_common_args: "-o IdentityAgent={{socket}}"
Ansible variable “socket” contains the path to the ssh-agent socket, the same value that is set in SSH_AUTH_SOCKET. That string (-o IdentityAgent={{socket}}) is passed to ssh when connecting to the target host and ssh uses that instead of SSH_AUTH_SOCK. The connection is made and all is well! I added “ansible_ssh_common_args” to the playbook vars section instead of at the individual tasks level and that works equally well.
The bottom line here is that I can now dynamically start ssh-agent, add keys to it, and then run tasks that use that ssh-agent to authenticate to hosts. The whole point of all of this is that I wanted to fetch keys from safe storage elsewhere and use them for client host access, all without ever writing the keys to file on the Ansible host. I think I have found a method of doing that here.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v_Vaf8k4%3DnPajbm_2e4oCv1Ayp%3DzRJiktD-qzXyuONN%2BA%40mail.gmail.com.
export AB_HOME=/et/dev/abinitio/abinitio-V3
export PATH=${AB_HOME}/bin:${PATH}
I have executed the env file using the below playbook and I tried to read the variables which are exported using the output1 which is a register variable in my playbook. But I am able to see my register variable is empty. Is there any way to get the variables which are all exported. I don't know the variables name which are present inside the file, So I am not able to use the ECHO command. Is there any work around for this
- hosts: dev
gather_facts: false
tasks:
- name: get the environment variables
shell: "su <id> & . ./.env"
args:
chdir: /path to the file
register: output1
- debug: var=output1.stdout_lines To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1a126537-a388-4a2a-81dc-108aa74ef27d%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/W0z5aMfhqDM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v9a4L-cpT6MkKn4RTsND8QguR89qVD%3DtVm3F0tEbPJSjA%40mail.gmail.com.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/VE1PR06MB63524B96F5545F064EA39AFC9E3C0%40VE1PR06MB6352.eurprd06.prod.outlook.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/W0z5aMfhqDM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v-yXH7F3Zo1FBQq5pDMPUxo5G1mRvJmsqjtK3JQyXAkGg%40mail.gmail.com.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/VE1PR06MB63522E11EC557DA9123FFB2B9E3C0%40VE1PR06MB6352.eurprd06.prod.outlook.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/W0z5aMfhqDM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible...@googlegroups.com.
I have the env file which is present in target machine and it contain certain number of variables with export command(the export command itself was present inside the file).
>
> export AB_HOME=/et/dev/abinitio/abinitio-V3
> export PATH=${AB_HOME}/bin:${PATH}
>
> I have executed the env file using the below playbook and I tried to read the variables which are exported using the output1 which is a register variable in my playbook. But I am able to see my register variable is empty. Is there any way to get the variables which are all exported. I don't know the variables name which are present inside the file, So I am not able to use the ECHO command as well.
>
> - hosts: dev
> gather_facts: false
> tasks:
> - name: get the environment variables
> shell: "su <id> & . ./.env"
> args:
> chdir: /path to the file
> register: output1
>
> - debug: var=output1.stdout_lines
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/ansible-project/422c885e-1894-4b8e-bd2b-84799e4fbd36%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/422c885e-1894-4b8e-bd2b-84799e4fbd36%40googlegroups.com>
> >
> <https://groups.google.com/d/msgid/ansible-project/422c885e-1894-4b8e-bd2b-84799e4fbd36%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/422c885e-1894-4b8e-bd2b-84799e4fbd36%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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