---
- name: Deploy
hosts: all
become: yes
tasks:
# INSTALL GIT ON REMOTE MACHINE
- name: Install GIT
apt:
pkg:
- git
# CLONE GIT REPO ON REMOTE MACHINE
- name: Connect to Bitbucket repo
git:
repo: ssh://user...@bitbucket.org/repository/repository.git
accept_hostkey: yes
version: master
dest: /home/username/git/
key_file: /home/username/.ssh/id_rsa
# FETCH YML FROM BITBUCKET
- name: Fetch yml from remote
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"
PLAY [Deploy] *****************************************************
TASK [Gathering Facts] *********************************************************
ok: [xxx.xxx.xxx.xxx]
TASK [Install GIT] *************************************************************
ok: [xxx.xxx.xxx.xxx] => {"cache_update_time": 1550376354, "cache_updated": false, "changed": false}
TASK [Connect to Bitbucket repo] ***********************************************
changed: [xxx.xxx.xxx.xxx] => {"after": "XXX", "before": "XXX", "changed": true, "remote_url_changed": false}
TASK [Fetch yml from remote] ***************************************************
ok: [xxx.xxx.xxx.xxx] => {"changed": false, "checksum": "xxxxxxxxx", "dest": "/playbook.yml", "file": "/home/username/git/playbookfolder/playbook.yml", "md5sum": "xxxxx"}
TASK [Run yml] *****************************************************************
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
[...]
# 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
[...]
[...]
TASK [Fetch yml from remote] ***************************************************15:19:2234ok: [xxx.xxx.xxx.xxx]3536TASK [Fetch and run other one] **************************************************15:19:2337ok: [xxx.xxx.xxx.xxx]3839PLAY RECAP *********************************************************************15:19:2340
[...]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
--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/882fd5b7-6bd6-4198-9b01-fea8f5ef47a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sorry, yes, too early for clear thinking. ;)
I was thinking of ansible-pull. I know Brian Coca that frequents
this forum had a github or galaxy entry on the subject some time
ago but I can't seem to find it. But this is a good reference (or
you can just do a 'man ansible-pull'):
http://manpages.ubuntu.com/manpages/trusty/man1/ansible-pull.1.html
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6525ddbb-60e1-4ca9-a6c3-ed0d000b3541%40googlegroups.com.
Yeah I have not tried to execute a playbook like that so I don't have anything to offer there. I've done your exact scenerio though using ansible-pull to run a playbook from my BitBucket repo.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/23b04766-2efc-4dda-b4ad-16349c0d92b5%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b98d17f7-35b2-46ed-91fc-1803f7477821%40googlegroups.com.
--