Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create config variables for file modes, user, group #530

Open
jamesmontalvo3 opened this issue Mar 31, 2017 · 3 comments
Open

Create config variables for file modes, user, group #530

jamesmontalvo3 opened this issue Mar 31, 2017 · 3 comments

Comments

@jamesmontalvo3
Copy link
Contributor

jamesmontalvo3 commented Mar 31, 2017

At present many Ansible tasks look like:

- name: Copy something
  copy:
    src: /path/to/src/XYZ
    dest: /path/to/dest/XYZ
    mode: 0755
    owner: someowner
    group: somegroup

Where the mode, owner, and group are hard-coded. These could easily conflict with other tasks/playbooks that interact with this file or directory. It would be good to have config variables like xyz_mode = 0755 and xyz_owner = someowner such that the above task could be rewritten:

- name: Copy something
  copy:
    src: /path/to/src/XYZ
    dest: /path/to/dest/XYZ
    mode: "{{ xyz_mode }}"
    owner: "{{ xyz_owner }}"
    group: "{{ xyz_group }}"

Perhaps this could be taken a step further, such that the configuration variable could be written as an object that looks like:

file_xyz:
  src: /path/to/src/xyz
  dest: /path/to/dest/xyz
  mode: 0755
  owner: someowner
  group: somegroup

And the task could be rewritten:

- name: Copy something
  copy:
    src: "{{ file_xyz.src }}"
    dest: "{{ file_xyz.dest }}"
    mode: "{{ file_xyz.mode }}"
    owner: "{{ file_xyz.owner }}"
    group: "{{ file_xyz.group }}"

That may be taking it too far, though.

@jamesmontalvo3
Copy link
Contributor Author

Add recursive: yes|no to config?

@jamesmontalvo3
Copy link
Contributor Author

Also go through roles and ensure all file mode changing tasks have a user/group/mode specified.

@jamesmontalvo3
Copy link
Contributor Author

jamesmontalvo3 commented May 28, 2019

Even better would be:

m_paths:
  data:
    path: "/opt/data-meza"
    owner: meza-ansible
    group: wheel
    mode: "0775"
    servers: all
  uploads:
    path: "/opt/data-meza/uploads"
    better_path: "{{ m_paths.data.path }}/uploads" # if possible to do something like this (prob not)
    owner: apache
    group: apache
    mode: "0775"
    servers: app-servers

Then could setup paths like:

- name: Setup paths
  file:
    path: "{{ item.path }}"
    state: directory
    mode: "{{ item.mode }}"
    owner: "{{ item.owner }}"
    group: "{{ item.group }}"
  with_items: "{{ m_paths }}"
  when: item.servers == "all" or inventory_hostname _is in any of item.servers_ # what if item.servers is a list?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant