There is a git module for this purpose which may work better for you.

https://docs.ansible.com/ansible/latest/modules/git_module.html#git-module


On 3/20/19 7:25 AM, TOB wrote:
Hi everyone,

short summary: I have a playbook from where I wanna start other playbooks hosted on Bitbucket. In short words: Got a server and want to clone repository on Bitbucket where are all the other playbooks which I want to run on the remote server.

|
----name:Deploy  hosts:all   become:yes   tasks:# INSTALL GIT ON REMOTE MACHINE-name:InstallGIT     apt:      pkg:-git # CLONE GIT REPO ON REMOTE MACHINE-name:Connectto Bitbucketrepo     git:      repo:ssh://[email protected]/repository/repository.git      accept_hostkey:yes       version:master       dest:/home/username/git/      key_file:/home/username/.ssh/id_rsa # FETCH YML FROM BITBUCKET-name:Fetchyml fromremote     fetch:      remote_src:yes       src:/home/username/git/playbookfolder/playbook.yml       dest:/       flat: yes   - name: Run yml     include_tasks: "/home/username/git/playbookfolder/playbook.yml"
|


It's cloning and saving the git repository on the host machine. But now I want to run a playbook / include tasks on it. It's trying to find the playbook on the Ansible controller but it should search on the remote server I cloned the repo to. Getting this one:

|
PLAY [Deploy]*****************************************************TASK [GatheringFacts]*********************************************************ok:[xxx.xxx.xxx.xxx]TASK [InstallGIT]*************************************************************ok:[xxx.xxx.xxx.xxx]=>{"cache_update_time":1550376354,"cache_updated":false,"changed":false}TASK [Connectto Bitbucketrepo]***********************************************changed:[xxx.xxx.xxx.xxx]=>{"after":"XXX","before":"XXX","changed":true,"remote_url_changed":false}TASK [Fetchyml fromremote]***************************************************ok:[xxx.xxx.xxx.xxx]=>{"changed":false,"checksum":"xxxxxxxxx","dest":"/playbook.yml","file":"/home/username/git/playbookfolder/playbook.yml","md5sum":"xxxxx"}TASK [Runyml]*****************************************************************fatal:[xxx.xxx.xxx.xxx]:FAILED!=>{"reason":"Unable to retrieve file contents\nCould not find or access '/home/username/git/playbookfolder/playbook.yml' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}PLAY RECAP *********************************************************************xxx.xxx.xxx.xxx :ok=4   changed=1   unreachable=0   failed=1
|



I'm pretty sure I'm using the wrong syntax, but cannot figure out which is the right one. This one here is working but it's not doing the things I wrote in those different playbooks.

|
[...]
# FETCH UBUNTU / UPGRADE FROM BITBUCKET
  - name: Fetch yml from remote
fetch:
  remote_src: yes
  src: /home/username/git/playbookfolder2/playbook1.yml
  dest: /
  flat: yes
  import_playbook: playbook1.yml

# FETCH INSTALL LAMP FROM BITBUCKET
  - name: Fetch and run other one
fetch:
  remote_src: yes
  src: /home/username/git/playbookfolder2/playbook2.yml
  dest: /
  flat: yes
  import_playbook: playbook2.yml
[...]

|


Results here are following:
|
[...] TASK [Fetch yml from remote] ***************************************************
15:19:22
34
ok: [xxx.xxx.xxx.xxx]
35
36
TASK [Fetch and run other one] **************************************************
15:19:23
37
ok: [xxx.xxx.xxx.xxx]
38
39
PLAY RECAP *********************************************************************
15:19:23
40

[...]
|


Thanks in advance for any help! :)
--
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 [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/882fd5b7-6bd6-4198-9b01-fea8f5ef47a1%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/882fd5b7-6bd6-4198-9b01-fea8f5ef47a1%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e449151f-f8b5-e876-f6fc-648636439dac%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to