Fetching file from remote server to github repository using Ansible script

26 views
Skip to first unread message

Pradeep Drall

unread,
Jul 4, 2018, 7:53:33 AM7/4/18
to Ansible Project
Fetching file from remote server to github repository using Ansible script
Server A -> remote server like httpd
Server B -> gihub repository

Dick Visser

unread,
Jul 5, 2018, 4:13:36 AM7/5/18
to ansible...@googlegroups.com
By the (limited) amount of information it looks like you want to
commit something.
The git module (https://docs.ansible.com/ansible/latest/modules/git_module.html)
is targeted toward checking out repos, not committing to them.
So I assume you'd have to structure it something like this:

1. use the git module to checkout your repo
2. use the get_url module to retrieve your file and save it in your repo
3. use the command or shell module to add the file and commit



-
> --
> 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/296f3db2-97a2-46bc-8488-272a058a6af7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
T: +31205304488
M: +31622698108
PGP key fingerprint: F575 58C6 62C6 FD5B A9CD 217C 2667 13D4 E6EF 488D

GÉANT Vereniging (Association) is registered with the Chamber of
Commerce in Amsterdam with registration number 40535155 and operates
in the UK as a branch of GÉANT Vereniging. Registered office:
Hoekenrode 3, 1102 BR Amsterdam, The Netherlands. UK branch address:
City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK.


Want to join us? We're hiring: https://www.geant.org/jobs

Pradeep Drall

unread,
Jul 5, 2018, 10:57:12 AM7/5/18
to ansible...@googlegroups.com
Hi Dick, 

Thanks for your reply. 

Actually I want to copy the httpd.conf file from httpd server and store into Github repository. When we change something into httpd.conf file then automatically this file will save into github repository (abc/backup folder). 

I am facing the issue to push the file from httpd server to github repo. I got the example from internet to checkout / download files from github repo to local machine , but didn't find example to copy the file from remote server into github repository directly. 

Please assist me. 

With best regards,
Pradeep Kumar


Thanks & regards,
Pradeep Kumar Drall
919711940167
skype - pradeep.kumar2607

On Thu, Jul 5, 2018 at 4:13 AM, Dick Visser <dick....@geant.org> wrote:
By the (limited) amount of information it looks like you want to
commit something.
The git module (https://docs.ansible.com/ansible/latest/modules/git_module.html)
is targeted toward checking out repos, not committing to them.
So I assume you'd have to structure it something like this:

1. use the git module to checkout your repo
2. use the get_url module to retrieve your file and save it in your repo
3. use the command or shell module to add the file and commit



-

On 4 July 2018 at 13:53, Pradeep Drall <drallp...@gmail.com> wrote:
> Fetching file from remote server to github repository using Ansible script
> Server A -> remote server like httpd
> Server B -> gihub repository
>
> --
> 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-project+unsubscribe@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
T: +31205304488
M: +31622698108
PGP key fingerprint: F575 58C6 62C6 FD5B A9CD 217C 2667 13D4 E6EF 488D

GÉANT Vereniging (Association) is registered with the Chamber of
Commerce in Amsterdam with registration number 40535155 and operates
in the UK as a branch of GÉANT Vereniging. Registered office:
Hoekenrode 3, 1102 BR Amsterdam, The Netherlands. UK branch address:
City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK.


Want to join us? We're hiring: https://www.geant.org/jobs
--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwPLAb6t13MMd%3D9-Ya4ngvrbBd8388wsP7m4fZ3i6h0eAw%40mail.gmail.com.

Dick Visser

unread,
Jul 5, 2018, 1:52:45 PM7/5/18
to ansible...@googlegroups.com
On 5 July 2018 at 16:57, Pradeep Drall <drallp...@gmail.com> wrote:
> Hi Dick,
>
> Thanks for your reply.
>
> Actually I want to copy the httpd.conf file from httpd server and store into
> Github repository. When we change something into httpd.conf file then
> automatically this file will save into github repository (abc/backup
> folder).

It seems you've somehow reversed the workflow.
The idea is that git is used to keep track of config file changes.
And form there you configure your web server.
So the git repository is "leading" - not the web server.

> I am facing the issue to push the file from httpd server to github repo. I
> got the example from internet to checkout / download files from github repo
> to local machine , but didn't find example to copy the file from remote
> server into github repository directly.

That is probably because no one else has such a workflow.
This is consistent with the observation above.

If you still want to "use" git this way, then the 3 step pseudo
playbook from my previous message would work (although I don't
recommend doing it).

There is no such thing as "copy the httpd.conf file from httpd server
and store into Github repository".
You'd have to clone the repo on the web server, commit the files, and
then push it.

When I find myself having to jump through many hoops do something
seemingly simple, it's usually an indication that I'm looking at the
wrong solution...

Regards

Dick



Dick

Drew Northup

unread,
Jul 5, 2018, 2:27:13 PM7/5/18
to Ansible Project
Pradeep,
It seem to me that you've got a horse / cart inversion problem. Ansible can make backup copies of the files it modifies, but backing up configuration to durable storage (off of the system being managed) is the job of something else. If you want a rapid / atomic way to revert changes use something like etckeeper (which can then be used to push a copy of what it stores elsewhere, but read the fine print very closely first).

Aside from that very minor addition, Dick's advice is sound.
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
T: +31205304488
M: +31622698108
PGP key fingerprint: F575 58C6 62C6 FD5B A9CD 217C 2667 13D4 E6EF 488D

GÉANT Vereniging (Association) is registered with the Chamber of
Commerce in Amsterdam with registration number 40535155 and operates
in the UK as a branch of GÉANT Vereniging. Registered office:
Hoekenrode 3, 1102 BR Amsterdam, The Netherlands. UK branch address:
City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK.


Want to join us? We're hiring: https://www.geant.org/jobs

--
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.

Pradeep Drall

unread,
Jul 6, 2018, 1:03:43 PM7/6/18
to ansible...@googlegroups.com, dick....@geant.org, drew.n...@maine.edu
Hi, 

Thanks for your email. 

1. I installed the git in my ansible server. 

2. Then I use template module and downloaded the httpd.conf file with backup from httpd server into my ansible server.
- template:
      src: /etc/httpd/conf/httpd.conf
      dest: /home/test/
      backup: yes
      owner: test

3. I can check out the file from github repo to my ansible Linux server machine but I am unable to commit the file from my ansible Linux server machine to github repository (www.github.com/PD/testrepo/backup) folder. 
 can we use "mode:  push" in yml file. 

Normally we use the following steps to push a file into github repo from local machine. 
 a. git pull  b. git add .  c. git commit -am "message"  d. git push origin master . how to follow these steps in ansible yml file. 
 
 - name: check out a git repository
    local_action:
      module: git
      dest: /home/test/git
      update: yes
      version: master

  I don't want to retrieve the file from github repo to local machine, I want to push the httpd.conf file from remote server to github repository backup folder. 
  
Regards,
Pradeep 

Thanks & regards,
Pradeep Kumar Drall
919711940167
skype - pradeep.kumar2607

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Pradeep Drall

unread,
Jul 10, 2018, 2:10:12 PM7/10/18
to ansible...@googlegroups.com, dick....@geant.org, Drew Northup
gentle reminder ...

Thanks & regards,
Pradeep Kumar Drall
919711940167
skype - pradeep.kumar2607

Dick Visser

unread,
Jul 10, 2018, 4:35:43 PM7/10/18
to Pradeep Drall, ansible...@googlegroups.com, drew.n...@maine.edu
Hi

On 6 July 2018 at 19:03, Pradeep Drall <drallp...@gmail.com> wrote:
>
> Hi,
>
> Thanks for your email.
>
> 1. I installed the git in my ansible server.
>
> 2. Then I use template module and downloaded the httpd.conf file with backup from httpd server into my ansible server.
> - template:
> src: /etc/httpd/conf/httpd.conf
> dest: /home/test/
> backup: yes
> owner: test

This is also the opposite of what 'template' is meant for.
And why do you need to backup if you're going to use git for "versioning"?

> 3. I can check out the file from github repo to my ansible Linux server machine but I am unable to commit the file from my ansible Linux server machine to github repository (www.github.com/PD/testrepo/backup) folder.
> can we use "mode: push" in yml file.

It seems you're mixing up ansible pull/push mode with git pull/push?

> Normally we use the following steps to push a file into github repo from local machine.
> a. git pull b. git add . c. git commit -am "message" d. git push origin master . how to follow these steps in ansible yml file.
>
> - name: check out a git repository
> local_action:
> module: git
> repo: https://github.com/PD/testrepo.git
> dest: /home/test/git
> update: yes
> version: master
>
> I don't want to retrieve the file from github repo to local machine, I want to push the httpd.conf file from remote server to github repository backup folder.


As explained twice before, your workflow isn't particularly useful.
I don't think it serves any purpose helping someone to force a round
peg in a square hole.
You are best off by changing your workflow to something more standard
and supportable.

Regards

Dick
Reply all
Reply to author
Forward
0 new messages