Hi there,
I’m running via Vagrant, so everything should be executing by default as vagrant user.
My configuration looks like this
config.vm.provision “ansible” do |ansible|
ansible.playbook = “…/playbooks/docker.yml”
ansible.sudo = true
ansible.host_key_checking = false
ansible.verbose = ‘vvvv’
end
The docker.yml file (stripped down) looks like this:
I’m not sure where you are saying a bug might lie, but you’ve only shown PART of the play above, so I can’t tell what you are doing with it.
If there was a bug with our user handling, I’m pretty positive we would have heard about it 1000x over, but this list is for helping people out with questions.
I would only ask that people not first assume they have found a bug, but instead ask for help with a problem.
I am no expert, but I think that what he is saying is that when he includes base.yml then his setting of sudo:no in the file that includes base.yml is overridden.
Thus his “possible bug with users” really translates as “possible bug with sudo being used when I don’t expect it”
It’s really to do with sudo usage and nothing to do with the user module (which was what I expected when I read the title).
I hope that this helps,
Adam
Yes, to clarify, “possible bug with sudo being used when I don’t expect it”.
I deleted everything but the code needed to demonstrate the (possible) bug.
That code, when run - as is, demonstrates the problem.
It is part of a larger effort to create an Ansible config to provision a Vagrant box, install a couple of packages, and check out a couple of projects from github R/W.
The reason I don’t want to hard code the vagrant username is that I want to use the playbooks to be independent of Vagrant, I want to reuse it on Amazon, Linode, etc.
The even larger goal is to create and share a couple of useful roles.
“That code, when run - as is, demonstrates the problem.”
That’s not what I wanted, I set sudo = no in the docker.yml.
There’s no variable called “sudo” you can just drop in a YAML file, which implies we need to see the full uncensored playbook to tell you what would need to be changed.
Can you perhaps share this with everyone on github or gist, etc?
Hi Michael,
I’ve put a POC in git@github.com:picsolvebryan/ansible-vagrant-poc.git
I’ve got it pinned down now.
What is actually happening, I’m guessing is the variable ansible_env is only getting set once per execution.
I was using {{ansible_env[‘HOME’]}} to figure out the correct location into which I would put a $HOME/.ssh/known_hosts file.
Using ansible_env was unreliable. If I included something that ran using sudo, it would set ansible_env[‘HOME’] to /root for the entire execution rather then regenerate it per-playbook.
My kludge is to get those vars from system utils and register them for use by tasks defined further down the file. Like so:
- name: Get value of unpriv user
shell: /usr/bin/id -un
register: effective_username
And this here, gives the correct homedir
- name: Get homedir of unpriv user
shell: “echo $HOME”
register: effective_homedir
ansible_env gets set when facts are gathered and of course user variables
depend on which user was used to gather those facts.
Yes. Well surmised. Is there any way to re-trigger the gathering inside a playbook?
I think this has been answered in a previous post.
https://groups.google.com/forum/#!searchin/ansible-project/$20facts$20gathered/ansible-project/AGuHOnCgpc4/XIKaAnP3I-UJ
re-run the setup module, to get updated ansible_env
tasks:
Thanks guys!