how to use register as a key in yaml?

ansible --version

ansible [core 2.11.1]

黄政 <hzgood123@gmail.com> 于2021年7月10日周六 下午1:57写道:

I would recommend you to come up with a data structure like -

vars:
my_data:

  • name: “{{netplan_ssid}}”
    password: “ChinaNet-2403”
    test: “ChinaNet-2403”

I can’t understand what your mean
I tried your method, I have no such luck
it can’t work for netplan

Abhijeet Kasurde <akasurde@redhat.com> 于2021年7月10日周六 下午2:01写道:

I am assuming that netplan_ssid is dynamically coming from wlo.output so you can do like this

(attachments)

"Netplan uses YAML description files to configure network ..."
https://www.linux.com/topic/distributions/how-use-netplan-network-configuration-tool-linux/

See the example of the data
https://github.com/vbotka/ansible-linux-postinstall/blob/master/vars/main.yml.sample#L304

the template
https://github.com/vbotka/ansible-linux-postinstall/blob/master/templates/netplan-conf.j2

and the task to configure Netplan
https://github.com/vbotka/ansible-linux-postinstall/blob/master/tasks/netplan.yml#L21

thank everyone and json
I have solve it by as following----

https://www.haiyun.me/archives/1280.html

https://github.com/mrlesmithjr/ansible-netplan/issues/17

  • hosts: ubuntu

# ip a|grep -E ‘: enp’|awk -F ‘:’ ‘{print $2}’|awk ‘{print $1}’

# iw dev|grep Interface|awk ‘{print $2}’

any_errors_fatal: true
tasks:

  • import_tasks: tasks/netplan/get_val.yml
  • import_tasks: tasks/netplan/setup_wlan.yml
  • name: Include the mrlesmithjr.netplan role
    include_role:
    name: mrlesmithjr.netplan
    vars:
    netplan_enabled: true
    netplan_remove_existing: true

netplan_config_file: /tmp/vlan8-vlan15-netplan.yaml

netplan_packages:

  • wpasupplicant
    netplan_configuration: ‘{
    “network”: {
    “ethernets”: {
    “{{enp.stdout}}”: {
    “dhcp4”: true,
    “optional”: true
    }
    },
    “wifis”: {
    “{{wlo.stdout }}”: {
    “dhcp4”: true
    “dhcp6”: false
    “access-points”: {
    “{{netplan_ssid}}”:{
    “password”: “{{netplan_password}}”
    }
    }
    }
    }
    }
    }’

Vladimir Botka <vbotka@gmail.com> 于2021年7月10日周六 下午3:28写道: