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.
self.data = data
self.host = data['host']
self.hostname = data['hostname']
self.conn_name = data['conn_name']
if ipam.ip:
self.guest_ip4_address = ipam.restart_ip
else:
self.guest_ip4_address = data['guest_ip4_address']
if ipam.ip:
self.guest_ip4_address_for_restart = ipam.ip
else:
self.guest_ip4_address_for_restart = data['guest_ip4_address_for_restart']
if ipam.gw:
self.guest_gw4_address = ipam.gw
else:
self.guest_gw4_address = data['guest_gw4_address']
self.template_ip = data['template_ip']
self.host = data['host']
self.hostname_hosts = data['hostname_hosts']
self.hostname_playbook_path = data['hostname_playbook']
self.ip_playbook_path = data['ip_playbook']
self.logger = logger
and at the yml file here is the line:
host: 'default'
hostname_hosts: '/full/path/of/the/file/hosts'
So i am setting the hosts file location i sent with my previous email.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/p8OzBaUbjpU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7cTCgv%2BGXOjcGXhewNSQT-B7CPM3%3DYPGL_ryG6yiD7rOw%40mail.gmail.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/p8OzBaUbjpU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7cTCgv%2BGXOjcGXhewNSQT-B7CPM3%3DYPGL_ryG6yiD7rOw%40mail.gmail.com.
def get_host(self, hostname):
if hostname not in self._hosts_cache:
self._hosts_cache[hostname] = self._get_host(hostname)
..
hosts_cache is empty.
Thats why it is throwing exception. Seems i am doing something wrong about defining an Inventory as host.
Here is my hosts file /Users/oyarimtepe/Dev/vmware/command-center/register/hosts
[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
I set it at
# 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)
Below are the variables:host: 'default'
hostname: 'somehostname'
suffix: 'xxx'
conn_name: 'ens192'
guest_ip4_address_for_restart: '10.35.101.220'
guest_ip4_address: '10.35.101.220/24'
guest_gw4_address: '10.35.101.1'
self.hostname_hosts is set as /Users/oyarimtepe/Dev/vmware/command-center/register/hosts. Is it true to use a file there?
Also the hosts part at variable_manager.extra_vars is default, is it true?
Any idea what i am doing wrong?
I also set the ansible.cfg path and below is the content
[defaults] hostfile = /Users/oyarimtepe/Dev/vmware/command-center/register/hosts inventory = /Users/oyarimtepe/Dev/vmware/command-center/register/hosts
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/p8OzBaUbjpU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7cTCgv%2BGXOjcGXhewNSQT-B7CPM3%3DYPGL_ryG6yiD7rOw%40mail.gmail.com.