Skip to content

Latest commit

 

History

History
153 lines (128 loc) · 8.66 KB

File metadata and controls

153 lines (128 loc) · 8.66 KB

Ansible Role jm1.cloudy.files

This role helps with assembling, copying, moving, deleting, editing, uploading and downloading files, directories and links, changing ownership and permissions, cloning git and subversion repositories, extracting archives, accessing web services and more from Ansible variables.

Role variable files_config defines a list of tasks which will be run by this role. Each task calls an Ansible module similar to tasks in roles or playbooks except that only few keywords such as when are supported. For example, to ensure the inventory name for the current Ansible host being iterated over in the play is in /etc/hosts define variable files_config in group_vars or host_vars as such:

files_config:
- ansible.builtin.lineinfile:
    path: /etc/hosts
    regexp: '\.1\s+{{ hostname }}'
    line: "{{ '{ip} {fqdn} {hostname}'.format(ip='127.0.0.1', fqdn=fqdn, hostname=hostname) }}"
    owner: root
    group: root
    mode: '0644'
  when: distribution_id | first in ['CentOS', 'Red Hat Enterprise Linux']
        or distribution_id in [['Debian', '10']]
- ansible.builtin.lineinfile:
    path: /etc/hosts
    regexp: '\.1\s+{{ hostname }}'
    line: "{{ '{ip} {fqdn} {hostname}'.format(ip='127.0.1.1', fqdn=fqdn, hostname=hostname) }}"
    owner: root
    group: root
    mode: '0644'
  when: distribution_id | first not in ['CentOS', 'Red Hat Enterprise Linux']
        and distribution_id not in [['Debian', '10']]
- ansible.builtin.lineinfile:
    path: /etc/hosts
    regexp: '::1\s+{{ hostname }}'
    line: '::1 {{ fqdn }} {{ hostname }}'
    owner: root
    group: root
    mode: '0644'

Tested OS images

Available on Ansible Galaxy in Collection jm1.cloudy.

Requirements

This role uses module(s) from collections community.general and jm1.ansible. To install these collections you may follow the steps described in README.md using the provided requirements.yml.

Variables

Name Default value Required Description
files_config [] false List of tasks to run 1 2 3

Dependencies

None.

Example Playbook

- hosts: all
  become: true
  vars:
    # Variables are listed here for convenience and illustration.
    # In a production setup, variables would be defined e.g. in
    # group_vars and/or host_vars of an Ansible inventory.
    # Ref.:
    # https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html
    # https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
    files_config:
    - name: Clone a git repository
      ansible.builtin.git:
        repo: https://github.com/ansible/ansible-examples.git
        dest: /src/ansible-examples
  roles:
  - name: Manage files, directories, links and more
    role: jm1.cloudy.files
    tags: ["jm1.cloudy.files"]

For instructions on how to run Ansible playbooks have look at Ansible's Getting Started Guide.

License

GNU General Public License v3.0 or later

See LICENSE.md to see the full text.

Author

Jakob Meng @jm1 (github, galaxy, web)

Footnotes

  1. Useful Ansible modules in this context could be assemble, blockinfile, capabilities, copy, fetch, file, get_url, git, lineinfile, replace, slurp, subversion, template, unarchive, uri and xattr.

  2. Tasks will be executed with jm1.ansible.execute_module which supports keyword when only.

  3. Tasks will be executed with jm1.ansible.execute_module which supports modules and action plugins only. Some Ansible modules such as ansible.builtin.meta and ansible.builtin.{include,import}_{playbook,role,tasks} are core features of Ansible, in fact not implemented as modules and thus cannot be called from jm1.ansible.execute_module. Doing so causes Ansible to raise errors such as MODULE FAILURE\nSee stdout/stderr for the exact error. In addition, Ansible does not support free-form parameters for arbitrary modules, so for example, change from - debug: msg="" to - debug: { msg: "" }.