Hi,

My current 'hosts' inventory file has sections for a dev/stage/production 
workflow, and I don't imagine it will ever have more than one or two 
servers in each section. eg

```
[devel]
192.0.2.10 hostname=devel fqdn=devel.example.com

[stage]
192.0.2.10 hostname=stage fqdn=stage.example.com

[production]
203.0.113.10 hostname=production fqdn=production.example.com

[testing]
192.0.2.24 hostname=testing fqdn=testing.example.com
203.0.113.11 hostname=remotest fqdn=remotest.example.com

```

I have a playbook at the moment that does most of the work - main.yml - and 
it uses an ansible specific user I called 'ansa' that's set in 
group_vars/all:
```
# A user just for ansible
ansible_ssh_user: ansa
ansible_ssh_private_key_file: /path/to/the/ssh/id_rsa
```

To set up this 'ansa' user I have a separate setup.yml.

All of this is working fine. What I want to do now is run the setup.yml 
play on different hosts, with different initial login requirements. Namely 
some servers will be created using vagrant, so I want to use vagrant as 
remote_user:
```
- hosts: all
  accelerate: false
  remote_user: vagrant
  sudo: yes

 vars:
    ansible_ssh_user: vagrant
    ansible_ssh_private_key_file: "~/.vagrant.d/insecure_private_key"

 tasks: etc...
```

and others without vagrant using a standard root login:
```
- hosts: all
  accelerate: false
  remote_user: root

  vars:
    ansible_ssh_user: root
    ansible_ssh_private_key_file: "~/.ssh/id_rsa"


  tasks: etc...
```

So, two interelated problems:
One, I'm duplicating code with two different versions of this setup.yml, 
I'd like to have a single setup.yml with logic to decide which remote_user 
and ansible_ssh_user to use. I'm not sure how to achieve that.

Two, if I have an inventory section as show above with a [testing] section 
and two hosts in it, one of which is vagrant based and one not, how can I 
specify the right version of setup to use? (assuming problem One is 
unanswered)

'ansible-playbook --limit testing vagrant-setup_do.yml' will throw an error 
for the other host.

So far I've not managed to find a better way to address this than simply 
commenting out hosts in the inventory file before running the setup play. 
Once the setup play has run the main.yml play will work fine with this 
inventory layout, its just the inital setup run that is clunky.

Suggestions for making the initial setup less clunky are welcome. Right now 
the only thing I can think of is to work outside of ansible, setting up the 
root account with vagrant to match that on the non-vagrant hosts, so I can 
have a single setup play.

Or given that setup only has to be run once per host, maybe I'm trying to 
hard and just need to accept a little manual work getting things set up...


 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d7604069-3eaa-4985-a233-947f93ca1306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to