Accessing inventory host variable in Ansible playbook

You are on the right track about hostvars. This magic variable is used to access information about other hosts. hostvars is a hash with inventory hostnames as keys. To access fields of each host, use hostvars[‘test-1’], hostvars[‘test2-1’], etc. ansible_ssh_host is deprecated in favor of ansible_host since 2.0. So you should first remove “_ssh” from inventory … Read more

How to loop over this dictionary in Ansible?

Hows this – hosts: localhost vars: war_files: server1: – file1.war – file2.war server2: – file1.war – file2.war – file3.war tasks: – name: Loop over subelements of the dictionary debug: msg: “Key={{ item.0.key }} value={{ item.1 }}” loop: “{{ war_files | dict2items | subelements(‘value’) }}” dict2items, subelements filters are coming in Ansible 2.6. FYI, if a … Read more

How do I pass username and password while using Ansible Git module?

You can use something like this: — – hosts: all gather_facts: no become: yes tasks: – name: install git package apt: name: git – name: Get updated files from git repository git: repo: “https://{{ githubuser | urlencode }}:{{ githubpassword | urlencode }}@github.com/privrepo.git” dest: /tmp Note: {{ githubpassword | urlencode }} is used here, if your … Read more

Ansible remote_user vs ansible_user

They both seem to be the same. Take a look here: https://github.com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55 # the magic variable mapping dictionary below is used to translate # host/inventory variables to fields in the PlayContext # object. The dictionary values are tuples, to account for aliases # in variable names. MAGIC_VARIABLE_MAPPING = dict( connection = (‘ansible_connection’,), remote_addr = (‘ansible_ssh_host’, … Read more

Unexpected Exception: name ‘basestring’ is not defined when invoking ansible2

Ansible below version 2.5 requires Python 2.6 or 2.7 on the control host: Control Node Requirements basestring is no longer available in Python 3. From What’s New In Python 3.0: The builtin basestring abstract type was removed. Use str instead. The str and bytes types don’t have functionality enough in common to warrant a shared … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)