ansible install software from source

Let's install a software from source in Ansible

install lldpd from source by ansible

show the content

1
cat lldpd.yml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
-   hosts: localhost
    name: lldpd installation
    vars:
        lldpd_version: 1.0.5
    tasks:
        -   name: Retrieve lldpd source code
            get_url:
                # TODO replace it
                url: https://media.luffy.cx/files/lldpd/lldpd-{{ lldpd_version }}.tar.gz
                dest: /tmp/lldpd-{{ lldpd_version }}.tar.gz
        -   name: Extract archive
            unarchive:
                # if configured like as the following, 'Retrieve lldpd source code' task can be removed
                # src: https://media.luffy.cx/files/lldpd/lldpd-{{ lldpd_version }}.tar.gz
                src: /tmp/lldpd-{{ lldpd_version }}.tar.gz
                dest: /tmp
        -   name: Configure install
            command: ./configure
            args:
                chdir: /tmp/lldpd-{{ lldpd_version }}
                creates: /tmp/lldpd-{{ lldpd_version }}/configure.status.log
        -   name: Build lldpd
            command: make
            args:
                chdir: /tmp/lldpd-{{ lldpd_version }}
                creates: /tmp/lldpd-{{ lldpd_version }}/make.status.log
        -   name: Install lldpd
            become: true
            command: make install
            args:
                chdir: /tmp/lldpd-{{ lldpd_version }}
                creates: /tmp/lldpd-{{ lldpd_version }}/make_install.status.log
        -   name: Create chroot for lldpd
            file:
                path: /usr/local/var/run/lldpd
                state: directory
        -   name: Create _lldpd group
            group:
                name: _lldpd
                state: present
        -   name: Create _lldpd user
            user:
                name: _lldpd
                group: _lldpd
                comment: lldpd user
        -   name: Remove build directory
            file:
                path: /tmp/lldpd-{{ lldpd_version }}
                state: absent
        -   name: Remove archive
            file:
                path: /tmp/lldpd-{{ lldpd_version }}.tar.gz
                state: absent
        -   name: Enable lldpd service
            systemd:
                name: lldpd
                enabled: true
                masked: false
        -   name: Start lldpd service
            systemd:
                name: lldpd
                state: started

run

1
ansible-playbook lldpd.yml
Licensed under CC BY-NC-SA 4.0
Last updated on Apr 30, 2020 10:45 UTC