1

I would like to use an ansible playbook to setup identical configurations for two different users on my localhost (i.e., admin & brian). Currently, the "common" role installs programs that are accessible by both users. In addition, I have settings that are user specific (e.g., desktop wallpaper). When I run my playbook, the user specific settings are updated from one user but not the other. For example, if I run my playbook the wallpaper for brian is changed but the wallpaper for admin is left untouched. I am aware of become_user, but do not want to that for every task that I run. Is it possible to define the hosts file or playbook in such a way that I can simply specify the users on localhost I want the playbook to run against?

I have tried Is there anyway to run multiple Ansible playbooks as multiple users more efficiently? on the per role level but am getting the following error:

fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "/usr/bin/python2: can't open file '/home/brian/.ansible/tmp/ansible-tmp-1525409723.54-208533437554058/apt.py': [Errno 13] Permission denied\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 2}


site.yml

---
- name: ansible master playbook
  hosts: localhost
  connection: local

  roles:
    - role: common


roles/common/tasks/main.yml

---
  - import_tasks: gsettings.yml


roles/common/tasks/gsettings.yml

---
- name:  Use 12 hr. clock format  
  dconf:
    key: "/org/gnome/desktop/interface/clock-format"
    value: "'12h'"
user2514157
  • 545
  • 6
  • 24

2 Answers2

0

In Ansible you have the option to launch the playbook as:

ansible-playbook playbooks/playbook.yml --user user

Please note that specifying a user can sometime conflict with a user defined in /etc/ansible/hosts.

(From Ansible documentation)

imjoseangel
  • 3,543
  • 3
  • 22
  • 30
  • I tried this and also updated my question for providing the user at the role level. Received following error: fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "/usr/bin/python2: can't open file '/home/brian/.ansible/tmp/ansible-tmp-1525409925.08-205708380153994/apt.py': [Errno 13] Permission denied\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 2} – user2514157 May 04 '18 at 05:02
  • Of course, your ansible_user needs to have permissions over the rest of the users in your destination host if not using become (group or other permissions). – imjoseangel May 04 '18 at 05:13
  • When I add become: yes, I get just another error (see below). Both admin & brian users are members of sudo and datashare groups (confirmed with groups command). fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "/usr/bin/python2: can't open file '/home/brian/.ansible/tmp/ansible-tmp-1525412401.55-267652965572235/dconf.py': [Errno 13] Permission denied\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 2} – user2514157 May 04 '18 at 05:40
  • I can't figure the file permissions out. Will changing remote_tmp in ansible.cfg help? – user2514157 May 04 '18 at 06:25
0

My solution was to simply log into each user on my local machine and run my ansible playbooks locally. An underlying issue with using the dconf module to change gsettings appears to be that D-Bus for the other user is not set, so the gsettings for the other user do not stick. See related questions below.

https://askubuntu.com/questions/655238/as-root-i-can-use-su-to-make-dconf-changes-for-another-user-how-do-i-actually

http://docs.ansible.com/ansible/latest/modules/dconf_module.html

Access another user's D-Bus session

user2514157
  • 545
  • 6
  • 24