For me it sounds like it should be possible. Ansible is not used yet anywhere. The nodes in Foreman report via Puppet. But this part should not be changed now.
Expected outcome:
I would like to get some examples of Ansible playbooks using this inventory collection, since I didn’t find anything in the docs.
Foreman and Proxy versions:
3.2.1 Foreman and Proxy plugin versions:
3.2.1 Distribution and version:
Ubuntu 20.04 LTS (server)
Thanks! @gvde I was able to run the example playbook.
But there it is about creating organizations in Foreman. I would like to fetch all host data (IP, name, etc) from an running Foreman instance to use them somewhere else.
Sometimes it felt like l am lost in a loop. Ansible Galaxy is pointing me to the same information on GH which also points to the Foreman docs with the same (or nearly the same content).
But this is another topic. Maybe some one is interested in this user experience and can improve it.
Get inventory hosts from Foreman. sounds best for my project. But Ansible always complains about the syntax. Maybe someone can give me help here, please?
I really hate that it is not allowed to edit the own posts afterwards.
But @gvde you are right. Pasting screenshots it not optimal.
Not that it is needed here, since you pointed into the correct way (Ansible Inventories), but maybe it helps someone that is searching for it. here the text outputs.
mf1045@pe-nb267:~/ansible/foreman$ cat my_foreman.yml
---
- name: "test"
hosts: localhost
tasks:
- name: show
plugin: theforeman.foreman.foreman
url: https://foreman.DOMAIN
user: USERNAME
password: PASSWORD
mf1045@pe-nb267:~/ansible/foreman$ ansible-playbook my_foreman.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost
does not match 'all'
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/home/mf1045/ansible/foreman/my_foreman.yml': line 7, column 10, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
plugin: theforeman.foreman.foreman
url: https://foreman.DOMAIN
^ here
mf1045@pe-nb267:~/ansible/foreman$ vim my_foreman.yml
mf1045@pe-nb267:~/ansible/foreman$ cat my_foreman.yml
---
- name: "test"
hosts: localhost
tasks:
- name: show
theforeman.foreman.foreman:
url: https://foreman.DOMAIN
user: USERNAME
password: PASSWORD
mf1045@pe-nb267:~/ansible/foreman$ ansible-playbook my_foreman.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost
does not match 'all'
ERROR! couldn't resolve module/action 'theforeman.foreman.foreman'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/mf1045/ansible/foreman/my_foreman.yml': line 5, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: show
^ here
mf1045@pe-nb267:~/ansible/foreman$ vim my_foreman.yml
mf1045@pe-nb267:~/ansible/foreman$ cat my_foreman.yml
plugin: theforeman.foreman.foreman:
url: https://foreman.DOMAIN
user: USERNAME
password: PASSWORD
host_filters: 'organization="Default Organization"'
mf1045@pe-nb267:~/ansible/foreman$ ansible-playbook my_foreman.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost
does not match 'all'
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/home/mf1045/ansible/foreman/my_foreman.yml': line 1, column 35, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
plugin: theforeman.foreman.foreman:
^ here
mf1045@pe-nb267:~/ansible/foreman$ cat foreman.yml
- name: "test"
hosts: localhost
tasks:
- name: show
theforeman.foreman.host_info:
server_url: "https://foreman.DOMAIN"
username: "USERNAME"
password: "PASSWORD"
search: "domain= DOMAIN"