When there's a foreman present in the environment, it's wise to use it as an inventory source for your ansible deployments since it will most likely always be up to date when it comes to hosts (single source of truth).
In order to use ansible as inventory, you'll have to define a *.foreman.yml file in your inventory which will then query the foreman for hosts, groups and variables which can then be used in ansible:
[archy@ansible ~/ansible]$ vim inventories/foreman/archyslife.foreman.yml
plugin: foreman
url: https://katello.archyslife.lan
user: roadmin
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000
use_reports_api: false
group_prefix: foreman_
varrs_prefix: foreman_
leading_separator: _
legacy_hostvars: false
validate_certs: false
want_content_facet_attributes: true
want_facts: true
want_host_group: true
want_hostcollections: false
want_ipv4: true
want_ipv6: false
want_location: true
want_organization: true
want_params: true
want_smart_proxies: true
want_subnet: true
want_subnet_v6: false
Note that I'm using an encrypted password here. To generate something like this you can use 'ansible-vault encrypt_string' like so:
[archy@ansible ~/ansible]$ ansible-vault encrypt_string 'super_secure_password' --vault-password-file ~/.pswdfle
Now let's try querying the inventory for all groups to check if it works:
[archy@ansible ~/ansible]$ ansible 'ansible.archyslife.lan' --inventory inventories/foreman --vault-password-file inventories/foreman/pswdfle --module-name debug --args 'var=groups'
This will print out all groups that were returned by foreman.
Keep in mind that the variable_prefixes as well as group_prefixes could be changed using the *.foreman.yml file.
Keep in mind that with AWX or Ansible Tower this can be done graphically using the WebUI.
Feel free to comment and / or suggest a topic.
Comments
Post a Comment