Hi,
first thing you should version all your playbooks and roles in a git
repository.
Then you tell Jenkins to pull such git repository and run the playbook you
want to.
Be sure that on the Jenkins host you have installed all the required
software: ansible, git.
You can create a Jenkinsfile at the root of your project that describes the
steps that Jenkins has to perform in order to run your playbook:
Example for my Jenkinsfile that does something on my aws instances:
pipeline {
agent any
environment {
AWS_ID = credentials("aws_credentials")
AWS_ACCESS_KEY_ID = "${env.AWS_ID_USR}"
AWS_SECRET_ACCESS_KEY = "${env.AWS_ID_PSW}"
ANSIBLE_VAULT_PASSWORD_FILE =
credentials("ansible-vault-password-file")
SSH_PRIVATE_KEY_FILE = credentials("ssh-private-key-file")
}
stages {
stage("prepare virtualenv") {
steps {
withPythonEnv('python') {
sh """
pip install -r ansible/pip/pip-requirements.txt
"""
}
}
}
stage("run playbook") {
steps {
withPythonEnv('python') {
sh """
cd ansible
ansible-playbook my-playbook.yml --extra-vars
"target=targethost" --private-key $SSH_PRIVATE_KEY_FILE
--vault-password-file $ANSIBLE_VAULT_PASSWORD_FILE
"""
}
}
}
}
}
On Wednesday, May 6, 2020 at 6:00:33 AM UTC+2, Kiran Kumar wrote:
>
> Thanks Vivek
>
> On Sat, May 2, 2020 at 11:56 PM Vivek Kothawale <[email protected]
> <javascript:>> wrote:
>
>> Hi
>>
>> To achieve the above mentioned objective you can wirte Jenkins file and
>> package all the files using fpm and deploy that package in jenkins server
>> and then you can run playbooks using ansible jenkins by providing path to
>> playbook.
>>
>> Thanks and Regards,
>> Vivek
>>
>> On Sun, May 3, 2020, 12:18 PM Dick Visser <[email protected]
>> <javascript:>> wrote:
>>
>>> This looks like a question about how to use git, in combination with
>>> Jenkins, neither of which this list is supporting. You might get more
>>> response from a support forum on Jenkins.
>>>
>>> On Sun, 3 May 2020 at 04:59, Kiran Kumar <[email protected]
>>> <javascript:>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I have a ansible server, which i use mainly to manage ntp client/dns
>>>> client/time zone/create users/install software etc on various linux
>>>> servers.. so no development to say, just as "infrastructure as code"
>>>>
>>>> On same server i installed Jenkins & on Jenkins i installed ansible
>>>> plugin. Now i have a UI ( Front end ) for my playbooks. So Jenkins runs
>>>> the
>>>> playbooks.
>>>>
>>>> So far so good.
>>>>
>>>> Now i am scratching my head & doing google ( and various online
>>>> training ) how do i ensure all those playbook & roles etc to add to GIT &
>>>> then manage with GIT.
>>>>
>>>> This is what i did so far
>>>>
>>>>
>>>> - Install git plugin of Jenkins on same server
>>>> - Install git server on same server, now this server acts as
>>>> Jenkins+Ansible + Git
>>>> - Test my git server by creating a project on it & testing with a
>>>> work-station
>>>>
>>>>
>>>>
>>>> All stuff on my ansible is under /etc/ansible ie playbook in
>>>> /etc/ansible/playbooks , roles in /etc/ansible/roles , inventory at
>>>> /etc/ansible/hosts
>>>>
>>>> Please suggest ( any good blog/web page/book ) or otherwise any
>>>> suggestions will help
>>>>
>>>> Thanks
>>>> Kiran
>>>>
>>>> --
>>>> 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] <javascript:>.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/ansible-project/826bc85c-41b5-4d86-86f3-88dfb82bf93f%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/ansible-project/826bc85c-41b5-4d86-86f3-88dfb82bf93f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> Sent from a mobile device - please excuse the brevity, spelling and
>>> punctuation.
>>>
>>> --
>>> 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] <javascript:>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/CAL8fbwOpwfghzGkpLuMgHBDC3ZU%2BR86vXELA2FKAyNRa6Zoxfg%40mail.gmail.com
>>>
>>> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwOpwfghzGkpLuMgHBDC3ZU%2BR86vXELA2FKAyNRa6Zoxfg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Ansible Project" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/ansible-project/_pGJftUckVk/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAA420E9FDhOJLro1nDR2%3Djtv3VnZbKTgPv-y7Y6_px-U8sgRCg%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/CAA420E9FDhOJLro1nDR2%3Djtv3VnZbKTgPv-y7Y6_px-U8sgRCg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/9081c018-9bb3-4919-808a-40a61982bbb8%40googlegroups.com.