Additional vars files with space in value

I am having a problem providing value through extra vars when I run my book using:

ansible-playbook gitolite-docker.yml -e "GITOLITE_SSH_KEY=$(cat roles/gitolite-docker/files/john_rsa.pub)" --ask-vault-pass

Here is an excerpt from gitolite-docker.yml

- name: logging admin.pub
  shell: echo "{{GITOLITE_SSH_KEY}}" > /home/ansusersu/gitoliteadmin.pub

- name: create gitolite--docker container
  docker_container: 
    name: gitolite
    image: alex2357/docker-gitolite
    state: started
    ports:
      - "8081:22"
    volumes:
      - "/docker/volumes/gitoliterepositories:/home/git/repositories"
    env:
      SSH_KEY: "{{GITOLITE_SSH_KEY}}"
      KEEP_USERS_KEYS: "dummytext"      
  become: yes 

The problem is that I only get the first few characters "ssh-rsa" from the SSH key.

john@john-VirtualBox:~$ sudo cat /home/ansusersu/gitoliteadmin.pub
ssh-rsa
john@john-VirtualBox:~$ 

I get exactly the same value in both applications {{GITOLITE_SSH_KEY}}. In the Docker container, I have the same meaning in the log files.

For Docker, a similar line works fine:

docker run -d -p 8081:22 --name gitolite -e SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" -v /docker/volumes/gitoliterepositories:/home/git/repositories alex2357/docker-gitolite

When I saw what seems to me, I can’t achieve the same behavior with Ansible-playbook as with Docker, because it considers the remaining staff as another additional var. Is there any way to make it work?

+4
1

:

ansible-playbook gitolite-docker.yml -e "GITOLITE_SSH_KEY='$(cat roles/gitolite-docker/files/john_rsa.pub)'" --ask-vault-pass

:

ansible-playbook gitolite-docker.yml -e "GITOLITE_SSH_KEY=\"$(cat roles/gitolite-docker/files/john_rsa.pub)\"" --ask-vault-pass
+3

Source: https://habr.com/ru/post/1665807/


All Articles