Problems with copy module

I have a problem with the ansible copy module.

We have a ansible-repository which I checked out on machine “A” and I have a second machine where I want to install jenkins, “B”. So I start ansible-playbook like this on machine “A”:

ansible-playbook -i integration jenkinsservers.yml --ask-pass -s

In my jenkins role I defined a task which should copy an private and a public key from machine “A” into the .ssh directory of the application-user on machine “B”:

  • name: create ssh directory for user ${app_name}
    file: path=/home/${app_name}/.ssh owner=${app_name} group=${app_name} state=directory

  • name: copy ${app_name} private key into place
    file: src=id_rsa dest=/home/${app_name}/.ssh/id_rsa owner=${app_name} group=${app_name} mode=600

  • name: copy ${app_name} public key into place
    file: src=id_rsa.pub dest=/home/${app_name}/.ssh/id_rsa.pub owner=${app_name} group=${app_name} mode=640

But when I run this, I get the following error:

TASK: [copy jenkins public key into place] ************************************
failed: [v00684.sbb.ch] => {“failed”: true, “item”: “”, “path”: “/home/jenkins/.ssh/id_rsa.pub”, “state”: “absent”}
msg: file (/home/jenkins/.ssh/id_rsa.pub) does not exist, use copy or template module to create

FATAL: all hosts have already failed – aborting

On the machine “B” I can see the directory, but no content.

PS: Ansible Version 1.3.3.

What I am doing wrong?

I would advise adding a shell command in your playbook to verify the host and content …

  • shell: hostname ; whoami; pwd ; ls -al /home/jenkins

first i would use the authorized_key module to do all in 1 step.

I think you misunderstand what is happening in these 2 tasks:

  • name: copy ${app_name} private key into place

file: src=id_rsa dest=/home/${app_name}/.ssh/id_rsa owner=${app_name} >group=${app_name} mode=600

  • name: copy ${app_name} public key into place
    file: src=id_rsa.pub dest=/home/${app_name}/.ssh/id_rsa.pub owner=${app_name} >group=${app_name} mode=640

they are NOT copying the file, you need to use the copy module for this.

Hello Brian

Thank’s for the tip with the module, I will use it.

Your second tip helped me with the copy operation. I was confused of the word copy in the “name:”-line, so I didn’t noticed the mistake.