# Ansible cloud openstack os\_server module userdata param : how to use it ?

**URL:** <https://forum.ansible.com/t/ansible-cloud-openstack-os-server-module-userdata-param-how-to-use-it/23689>\
**Category:** Ansible Developer\
**Created:** [February 9, 2017, 10:58am UTC](https://forum.ansible.com/t/ansible-cloud-openstack-os-server-module-userdata-param-how-to-use-it/23689 "2017-02-09T10:58:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain\_GINIBRE](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sylvain\_GINIBRE](https://forum.ansible.com/u/Sylvain_GINIBRE)\
**Post date:** [February 9, 2017, 10:58am UTC](https://forum.ansible.com/t/ansible-cloud-openstack-os-server-module-userdata-param-how-to-use-it/23689/1 "2017-02-09T10:58:26Z")

</div>

Hi,

I try to make an intance using os\_server module and a cloud-config file using the userdata parameter.

- **name: Deploy a CentOS-7 instance**  
**os\_server** :  
cloud: myCloud  
state: present  
name: “{{ inventory\_hostname }}”  
key\_name: ansible  
image: ‘CentOS-7’  
timeout: 300  
flavor: ‘m1.medium’  
auto\_ip: no  
security\_groups: ‘std’  
meta:  
hostname: “{{ inventory\_hostname }}”  
**userdata** : |  
#cloud-config  
bootcmd:
- [cloud-init-per, once, ‘bootcmd-disable-repos’, ‘bash’, ‘-c’ 'yum-config-manager --disable $( sed -e “/^[/!d ; s/^[([^]]_)]._$/\1/g” /etc/yum.repos.d/\*.repo ) ’ ]  
yum\_repos:  
Custom-Repos-BASE:  
name: Custom Repos - CentOS-$releasever - BASE  
baseurl: [http://my.repos.lan/centos/$releasever/os/$basearch/](http://my.repos.lan/centos/$releasever/os/$basearch/)  
gpgcheck: true  
gpgkey: [http://my.repos.lan/centos/7/os/x86\_64/RPM-GPG-KEY-CentOS-7](http://my.repos.lan/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7)  
enabled: true

but on the server :

**[centos@test-t ~]$ sudo cat /var/lib/cloud/instances/i-0000f7b6/cloud-config.txt**  
#cloud-config

— {}  
…  
**[centos@test-t ~]$[centos@test-t ~]$ ls -la /etc/yum\***  
-rw-r–r–. 1 root root 970 3 déc. 2015 /etc/yum.conf

/etc/yum:  
total 28  
drwxr-xr-x. 6 root root 4096 5 sept. 11:55 .  
drwxr-xr-x. 78 root root 8192 9 févr. 10:03 …  
drwxr-xr-x. 2 root root 6 3 déc. 2015 fssnap.d  
drwxr-xr-x. 2 root root 52 5 sept. 11:59 pluginconf.d  
drwxr-xr-x. 2 root root 25 5 sept. 11:55 protected.d  
drwxr-xr-x. 2 root root 18 3 déc. 2015 vars  
-rw-r–r–. 1 root root 444 3 déc. 2015 version-groups.conf  
-rw-r–r–. 1 root root 2534 3 déc. 2015 yum-cron.conf  
-rw-r–r–. 1 root root 2496 3 déc. 2015 yum-cron-hourly.conf

/etc/yum.repos.d:  
total 44  
drwxr-xr-x. 2 root root 4096 3 déc. 2015 .  
drwxr-xr-x. 78 root root 8192 9 févr. 10:03 …  
-rw-r–r–. 1 root root 1664 9 déc. 2015 CentOS-Base.repo  
-rw-r–r–. 1 root root 1309 9 déc. 2015 CentOS-CR.repo  
-rw-r–r–. 1 root root 649 9 déc. 2015 CentOS-Debuginfo.repo  
-rw-r–r–. 1 root root 290 9 déc. 2015 CentOS-fasttrack.repo  
-rw-r–r–. 1 root root 630 9 déc. 2015 CentOS-Media.repo  
-rw-r–r–. 1 root root 1331 9 déc. 2015 CentOS-Sources.repo  
-rw-r–r–. 1 root root 1952 9 déc. 2015 CentOS-Vault.repo

Maybe I’m wrong, but the cloud-config file should not be empty and my added repos should be in the list.

I need to use a sort of template file as userdata parameter. In this parameter I need to use the inventory\_hostname variable (among others).

Any help please ?

Thanks
