Here is my structure.
✗ tree -L 2
.
├── ansible.cfg
├── ansible.cfg.bak
├── group_vars
│ ├── default
│ └── default.bak
├── hosts
├── playbook.yml
├── playbook_hostname.yml
├── playbook_ip.yml
├── roles
│ ├── hostname
│ ├── ip
│ └── satellite
When i run the below code, i am not able to connect to the remote machine.
When i check with tcpdump, no connection request is sent, it seems somehow
no connection details are read from inventory files.
This is the error i saw when i install the ansible 2.0.0.1
raise AnsibleError("no host vars as host is not in inventory: %s" %
hostname)
ansible.errors.AnsibleError: ERROR! no host vars as host is not in
inventory: 10.35.75.247
def run(self):
Options = namedtuple('Options', ['listtags', 'listtasks', 'listhosts',
'syntax', 'connection', 'module_path',
'forks',
'remote_user', 'private_key_file',
'ssh_common_args',
'ssh_extra_args', 'sftp_extra_args',
'scp_extra_args', 'become',
'become_method', 'become_user',
'verbosity', 'check'])
variable_manager = VariableManager()
loader = DataLoader()
options = Options(listtags='', listtasks='', listhosts='', syntax='',
connection='paramiko', module_path='', forks=5,
remote_user='root',
private_key_file='', ssh_common_args='',
ssh_extra_args='',
sftp_extra_args='', scp_extra_args='', become=True,
become_method='sudo',
become_user='root', verbosity=1, check='')
passwords = dict(conn_pass='xxxx', become_pass='xxxx')
# create inventory and pass to var manager
inventory = Inventory(loader=loader, variable_manager=variable_manager,
host_list=self.hostname_hosts)
variable_manager.extra_vars = {'hosts': self.host, 'hostname':
self.hostname,
'conn_name': self.conn_name,
'guest_ip4_address': self.guest_ip4_address,
'guest_ip4_address_for_restart':
self.guest_ip4_address_for_restart,
'guest_gw4_address': self.guest_gw4_address,
'template_ip': self.template_ip} # This can accomodate various other command
line arguments.`
variable_manager.set_inventory(inventory)
self.logger.info("Running the playbook: changing the hostname and setting
ip")
pbex = PlaybookExecutor(playbooks=[self.hostname_playbook_path,
self.ip_playbook_path], inventory=inventory,
variable_manager=variable_manager, loader=loader,
options=options, passwords=passwords)
results = pbex.run()
Here is ansible.cfg
[defaults]
inventory = hosts
here is hosts file:
[local]
127.0.0.1 ansible_python_interpreter=python
[default]
10.35.75.247 ansible_python_interpreter=python ansible_user=root
ansible_ssh_pass=xxxx
the group_vars/default is empty.
and the playbook_hostname.yml is here
---
- name: Set the hostname
hosts: default
roles:
- hostname
Any idea now?
somehow i am not using the right method to read inventory and its predefined
settings. Will be great if someone help.
--
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/d68653e2-7af4-40de-bbdc-339cd02e797a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.