After struggling to fix the problem i am back to the list again. Seems i have a problem about reading my Inventory. I am not able to find the problem so i need help:
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='ssh', 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=False)
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()
self.logger.info("Playbook run is ended")
self.hostname_hosts is a 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
Somehow when i run the python code, it is not able to connect to the remote host.
So is there any wrong usage above? Is the inventory right? I even tried with removing ansible variabled at the line, nothing changed.
Any idea? I am using the lates ansible pip module. I tried with the previous version but nothing changed. Will be happy if someone give a clue.
--