# Mac provisioning: running PlistBuddy or sqlite3 from a playbook doesn't work

**URL:** <https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983>\
**Category:** Ansible Project\
**Created:** [August 19, 2014, 9:16am UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983 "2014-08-19T09:16:32Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 19, 2014, 9:16am UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/1 "2014-08-19T09:16:32Z")

</div>

I’m writing a Mac setup playbook and am borrowing heavily from various “dotfiles” around the web to help with configuring certain aspects of OS X.

Here’s my current dotfile which is effectively just a bash script:

[https://bitbucket.org/dbohea/mac-setup-playbook/src/0b4d30a3e44a16462d94808c66e15eba0aa44f7d/osx.sh?at=master](https://bitbucket.org/dbohea/mac-setup-playbook/src/0b4d30a3e44a16462d94808c66e15eba0aa44f7d/osx.sh?at=master)

This runs just fine directly from the command line. Oddly, when run from an Ansible playbook, none of the PlistBuddy or sqlite3 commands seem to work.

Anyone know why this may be or what I can do to fix it?

PS - Before anyone suggests it, it’s nothing to do with the if statement at the end of the file - I’ve tested this.

---

<div class="post-metadata">

**Author:** ![Mark\_McCoy](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@Mark\_McCoy](https://forum.ansible.com/u/Mark_McCoy)\
**Post date:** [August 19, 2014, 1:30pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/2 "2014-08-19T13:30:39Z")

</div>

It’s probable something to do with the PATH in your bash environment. When you login interactively, the .profile rc file gets run and normally sets up the PATH. I would imagine that when you login via ansible you don’t have the directory for PlistBuddy or sqlite3 in your PATH so those commands fail.

You can either fiddle with your ssh\_args in the ansible config files to tell ssh to make the shell a login shell, or you can just put the full path to Sqlite3 and PlistBuddy on those lines of your .bashrc file.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 19, 2014, 4:43pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/3 "2014-08-19T16:43:03Z")

</div>

Thanks Mark - I’ll take a closer look at that and post my findings back here.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 19, 2014, 4:50pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/4 "2014-08-19T16:50:44Z")

</div>

Thanks to some advice from elsewhere, I did try to run “shell: which sqlite3” from within my playbook and then compared the output to what I receive when I run “which sqlite3” in the command line. The results are the same.

If there was a PATH issue with Ansible trying to run sqlite3, wouldn’t the above test fail (i.e. output from each command wouldn’t match)?

---

<div class="post-metadata">

**Author:** ![Mark\_McCoy](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@Mark\_McCoy](https://forum.ansible.com/u/Mark_McCoy)\
**Post date:** [August 19, 2014, 7:41pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/5 "2014-08-19T19:41:21Z")

</div>

Yes, if the which command found the binary from within ansible, then it should find it when running the script via ansible. That seems pretty odd that it doesn’t. I know that the script asks for the sudo password so you can run it locally, but does it run via sudo when run by ansible? If so then it would be using root’s path and not yours.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 20, 2014, 1:44am UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/6 "2014-08-20T01:44:19Z")

</div>

Can I see the playbook line in question.

Many things don’t trust the system path, but most of them do. The command module is one of those things.

Though if you need explicit environment variable control, take a look here:

[http://docs.ansible.com/playbooks\_environment.html](http://docs.ansible.com/playbooks_environment.html)

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 20, 2014, 10:20am UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/7 "2014-08-20T10:20:45Z")

</div>

Sure, the role that attempts to run the bash script is here:

[https://bitbucket.org/dbohea/mac-setup-playbook/src/414cda3c20b9e20d82c34a2776d0d0c34b6c5d97/roles/osx/tasks/main.yml?at=master](https://bitbucket.org/dbohea/mac-setup-playbook/src/414cda3c20b9e20d82c34a2776d0d0c34b6c5d97/roles/osx/tasks/main.yml?at=master)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 20, 2014, 1:10pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/8 "2014-08-20T13:10:20Z")

</div>

Ok so from your playbook:

- name: Execute .osx

```auto
  # TODO: doesn't run commands that use PlistBuddy or sqlite3
  shell: ./osx.sh --ansible
  notify: killall

```

```auto

```

```auto
Inside osx.sh are PlistBuddy and sqlite3 absolute-pathed? I assume they are not. I suspect they are in a path defined in your local environment, and won't be in the path for ansible, because of the way we enforce centralized and reliable configurations - not trusting 500 servers who might all have different .bashrcs, etc, we don't log in with interactive shells.

```

```auto

```

```auto
You'll want to read this section:

```

```auto

```

```auto
[http://docs.ansible.com/playbooks_environment.html](http://docs.ansible.com/playbooks_environment.html)

```

```auto

```

```auto
Then:

```

```auto

```

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 20, 2014, 1:27pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/9 "2014-08-20T13:27:46Z")

</div>

Thanks for looking.

PlistBuddy is called with an absolute path in osx.sh (see lines 198-205 for example):

[https://bitbucket.org/dbohea/mac-setup-playbook/src/0b4d30a3e44a16462d94808c66e15eba0aa44f7d/osx.sh?at=master](https://bitbucket.org/dbohea/mac-setup-playbook/src/0b4d30a3e44a16462d94808c66e15eba0aa44f7d/osx.sh?at=master)

I added the following but it doesn’t seem tt make a difference (sqlite3 doesn’t seem to get run):

`

- name: Execute .osx

# TODO: doesn’t run commands that use PlistBuddy or sqlite3

shell: ./osx.sh --ansible  
notify: killall  
environment:  
PATH: “/usr/bin:/usr/bin/sqlite3/bin”  
`

I also tried the following but still no dice:

`PATH: "/usr/bin:/usr/bin/sqlite3"`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 20, 2014, 1:31pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/10 "2014-08-20T13:31:30Z")

</div>

If it’s absolutely pathed that shouldn’t matter and shouldn’t be an ansible thing.

When you say it’s not being run, perhaps this is an issue with your shell script.

Ansible will tell you if the script failed and returned a non-zero status, of course, and can include output from the script if you want to add some debug.

However, if plist buddy does call sqlite and sqlite is in a different path (I don’t know ANYTHING about plistbuddy) you would still need to set the path stuff.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 20, 2014, 2:06pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/11 "2014-08-20T14:06:40Z")

</div>

The script runs as expected when run directly from the command line. Admittedly, I’ve copied and tweaked the script - it wasn’t written to be run from Ansible.

I know nothing about plistbuddy either 🙂 but it and sqlite3 are being called by different parts of the shell script - I don’t think they’re calling each other.

I’m gonna put this on the shelf and fallback to running this script _after_ the playbook, directly from the command line. Not really the Ansible way I know but I can’t spend any more time on it right now.

Thanks for all your help. If you get any bright ideas, please post them!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 20, 2014, 4:34pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/12 "2014-08-20T16:34:21Z")

</div>

Please try the path thing first, if sqlite is not at the default paths but is something configured in the user environment, that would explain why the shell script and plist buddy couldn’t find it.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 20, 2014, 5:11pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/13 "2014-08-20T17:11:47Z")

</div>

I appreciate your persistence Michael 🙂 Thanks for all your help so far.

I did try the path thing (a few comments up where I quoted some code snippets) but it didn’t seem to make any difference. The locations that I added to PATH could have been incorrect of course - I based them on what was returned from running the following:

`which sqlite3`

This returns:

`  
/usr/bin/sqlite3

`

If I run “echo $PATH” from within my playbook I get:

`

/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

`

As you can see, “usr/bin” is in there.

Am I missing something obvious here? I’m not a sys-admin as I’m sure you can tell. Do I need to add that massive PATH above via Ansible’s environment module?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 20, 2014, 6:14pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/14 "2014-08-20T18:14:33Z")

</div>

Yeah since it’s in /usr/bin that is most definitely _NOT_ a path thing.

I’m not sure what the failure mode here was, possibly the script died when it saw a shell wasn’t interactive?

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 20, 2014, 6:38pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/15 "2014-08-20T18:38:24Z")

</div>

OK, good to rule the PATH out then.

Not sure what you mean by failure mode but here’s the -vvvv output for the task that tries to run the script in case that helps. As you can see, “stderr” and “stdout” don’t seem to have anything to say.

`

TASK: [osx | Execute .osx] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\<127.0.0.1\> REMOTE\_MODULE command ./osx.sh --ansible #USE\_SHELL

\<127.0.0.1\> EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1408559599.6-238488648926013 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1408559599.6-238488648926013 && echo $HOME/.ansible/tmp/ansible-tmp-1408559599.6-238488648926013’]

\<127.0.0.1\> PUT /var/folders/5d/ry1gfqbx0rs8bmpy7lw0909w0000gn/T/tmpjDc9QL TO /Users/danbohea/.ansible/tmp/ansible-tmp-1408559599.6-238488648926013/command

\<127.0.0.1\> EXEC [‘/bin/sh’, ‘-c’, u’LANG=en\_US.UTF-8 LC\_CTYPE=en\_US.UTF-8 /usr/bin/python /Users/danbohea/.ansible/tmp/ansible-tmp-1408559599.6-238488648926013/command; rm -rf /Users/danbohea/.ansible/tmp/ansible-tmp-1408559599.6-238488648926013/ \>/dev/null 2\>&1’]

changed: [127.0.0.1] =\> {“changed”: true, “cmd”: “./osx.sh --ansible”, “delta”: “0:00:01.105129”, “end”: “2014-08-20 11:33:20.811287”, “rc”: 0, “start”: “2014-08-20 11:33:19.706158”, “stderr”: “”, “stdout”: “”}

`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 20, 2014, 6:42pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/16 "2014-08-20T18:42:33Z")

</div>

I mean this by “the way in which something fails”.

Yeah, I have no idea here.

Your script returned a non-zero exit code and no output, which is all ansible knows. It would depend on the behavior of the script. And that script may not have proper error handling to say why what was called in that script died.

I’d start by adding extra output to your script, etc.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 20, 2014, 6:53pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/17 "2014-08-20T18:53:44Z")

</div>

OK, I’ll do some more poking & prodding and see what I can turn up. Thanks again.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 21, 2014, 2:40pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/18 "2014-08-21T14:40:19Z")

</div>

Cracked it! It absolutely was down to errors in the script that I was just missing: one I’d inherited from where I’d copied it from (the sqlite3 command) and another of my own doing that was attempting to change a property in a file that didn’t exist yet.

Thank you sooooooo much for all your help and for pushing me to see this through proper style 😃

This playbook is gonna rock hard!

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [August 21, 2014, 2:41pm UTC](https://forum.ansible.com/t/mac-provisioning-running-plistbuddy-or-sqlite3-from-a-playbook-doesnt-work/15983/19 "2014-08-21T14:41:26Z")

</div>

UPDATE: running either works just fine.
